iosanimationWithKeyPath
2016-02-17 11:01
375 查看
animationWithKeyPath的值:
transform.scale = 比例轉換
transform.scale.x = 闊的比例轉換
transform.scale.y = 高的比例轉換
transform.rotation.z = 平面圖的旋轉
transform.translation.x
transform.translation.y
transform.translation.z
opacity = 透明度
margin
zPosition
backgroundColor 背景颜色
cornerRadius 圆角
borderWidth
bounds
contents
contentsRect
cornerRadius
frame
hidden
mask
masksToBounds
opacity
position
shadowColor
shadowOffset
shadowOpacity
shadowRadius
iOS Developer LibraryDeveloper
Search
Introduction
Core Animation Basics
Setting Up Layer Objects
Animating Layer Content
Building a Layer Hierarchy
Advanced Animation Tricks
Changing a Layer’s Default Behavior
Improving Animation Performance
Appendix A: Layer Style Property Animations
Appendix B: Animatable Properties
Appendix C: Key-Value Coding Extensions
Revision History
NextPrevious
You can also retrieve the value for arbitrary keys like you would retrieve the value for other key paths. For example, to retrieve the value of the
OS X Note: The
To provide a default value for a key, create a subclass of the desired class and override its
Listing C-1 Example implementation of defaultValueForKey:
Table C-1 Wrapper classes for C types
Table C-2 Transform field value key paths
The following example shows how you can modify a layer using the
https://developer.apple.com/library/prerelease/ios/releasenotes/General/iOS80APIDiffs/frameworks/QuartzCore.html https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreAnimation_guide/Key-ValueCodingExtensions/Key-ValueCodingExtensions.html#//apple_ref/doc/uid/TP40004514-CH12-SW2
transform.scale = 比例轉換
transform.scale.x = 闊的比例轉換
transform.scale.y = 高的比例轉換
transform.rotation.z = 平面圖的旋轉
transform.translation.x
transform.translation.y
transform.translation.z
opacity = 透明度
margin
zPosition
backgroundColor 背景颜色
cornerRadius 圆角
borderWidth
bounds
contents
contentsRect
cornerRadius
frame
hidden
mask
masksToBounds
opacity
position
shadowColor
shadowOffset
shadowOpacity
shadowRadius
iOS Developer LibraryDeveloper
Search
Core Animation Programming Guide
Table of ContentsIntroduction
Core Animation Basics
Setting Up Layer Objects
Animating Layer Content
Building a Layer Hierarchy
Advanced Animation Tricks
Changing a Layer’s Default Behavior
Improving Animation Performance
Appendix A: Layer Style Property Animations
Appendix B: Animatable Properties
Appendix C: Key-Value Coding Extensions
Revision History
NextPrevious
Key-Value Coding Extensions
Core Animation extends theNSKeyValueCodingprotocol as it pertains to the
CAAnimationand
CALayerclasses. This extension adds default values for some keys, expands wrapping conventions, and adds key path support for
CGPoint,
CGRect,
CGSize, and
CATransform3Dtypes.
Key-Value Coding Compliant Container Classes
TheCAAnimationand
CALayerclasses are key-value coding compliant container classes, which means that you can set values for arbitrary keys. Even if the key
someKeyis not a declared property of the
CALayerclass, you can still set a value for it as follows:
[theLayer setValue:[NSNumber numberWithInteger:50] forKey:@"someKey"]; |
someKeypath set previously, you would use the following code:
someKeyValue=[theLayer valueForKey:@"someKey"]; |
CAAnimationand
CALayerclasses, which automatically archive any additional keys that you set up for instances of those classes, support the
NSCodingprotocol.
Default Value Support
Core Animation adds a convention to key value coding whereby a class can provide a default value for a key that has no set value. TheCAAnimationand
CALayerclasses support this convention using the
defaultValueForKey:class method.
To provide a default value for a key, create a subclass of the desired class and override its
defaultValueForKey:method. Your implementation of this method should examine the key parameter and return the appropriate default value. Listing C-1 shows a sample implementation of the
defaultValueForKey:method for a layer object that provides a default value for the
masksToBoundsproperty.
Listing C-1 Example implementation of defaultValueForKey:
+ (id)defaultValueForKey:(NSString *)key |
{ |
if ([key isEqualToString:@"masksToBounds"]) |
return [NSNumber numberWithBool:YES]; |
return [super defaultValueForKey:key]; |
} |
Wrapping Conventions
When the data for a key consists of a scalar value or C data structure, you must wrap that type in an object before assigning it to the layer. Similarly, when accessing that type, you must retrieve an object and then unwrap the appropriate values using the extensions to the appropriate class. Table C-1 lists the C types commonly used and the Objective-C class you use to wrap them.C type | Wrapping class |
---|---|
CGPoint | NSValue |
CGSize | NSValue |
CGRect | NSValue |
CATransform3D | NSValue |
CGAffineTransform | NSAffineTransform(OS X only) |
Key Path Support for Structures
TheCAAnimationand
CALayerclasses lets you access the fields of selected data structures using key paths. This feature is a convenient way to specify the field of a data structure that you want to animate. You can also use these conventions in conjunction with the
setValue:forKeyPath:and
valueForKeyPath:methods to set and get those fields.
CATransform3D Key Paths
You can use the enhanced key path support to retrieve specific transformation values for a property that contains aCATransform3Ddata type. To specify the full key path for a layer’s transforms, you would use the string value
transformor
sublayerTransformfollowed by one of the field key paths in Table C-2. For example, to specify a rotation factor around the layer’s z axis, you would specify the key path
transform.rotation.z.
Field Key Path | Description |
---|---|
rotation.x | Set to an NSNumberobject whose value is the rotation, in radians, in the x axis. |
rotation.y | Set to an NSNumberobject whose value is the rotation, in radians, in the y axis. |
rotation.z | Set to an NSNumberobject whose value is the rotation, in radians, in the z axis. |
rotation | Set to an NSNumberobject whose value is the rotation, in radians, in the z axis. This field is identical to setting the rotation.zfield. |
scale.x | Set to an NSNumberobject whose value is the scale factor for the x axis. |
scale.y | Set to an NSNumberobject whose value is the scale factor for the y axis. |
scale.z | Set to an NSNumberobject whose value is the scale factor for the z axis. |
scale | Set to an NSNumberobject whose value is the average of all three scale factors. |
translation.x | Set to an NSNumberobject whose value is the translation factor along the x axis. |
translation.y | Set to an NSNumberobject whose value is the translation factor along the y axis. |
translation.z | Set to an NSNumberobject whose value is the translation factor along the z axis. |
translation | Set to an NSValueobject containing an NSSizeor CGSizedata type. That data type indicates the amount to translate in the x and y axis. |
setValue:forKeyPath:method. The example sets the translation factor for the x axis to 10 points, causing the layer to shift by that amount along the indicated axis.
[myLayer setValue:[NSNumber numberWithFloat:10.0] forKeyPath:@"transform.translation.x"]; |
相关文章推荐
- IOS storyboard解决TableViewCell底线无法到头问题
- iOS实现图片保存与搜索功能
- iOS中的预编译指令的初步探究
- iOS: 常用的宏
- IOS各种调试技巧
- iOS清除xcode缓存和生成文件
- IOS开发证书变成“此证书的签发者无效”解决方法
- iOS -OPenGL的屏幕截图
- iOS闹钟实现
- Missing iOS Distribution signing identity for XXXXXX问题
- IOS NSInvocation应用与理解
- iOS 苹果开发证书失效的解决方案(Failed to locate or generate matching signing assets)
- iOS Provisioning Profile(Certificate)与Code Signing详解
- iOS: 复选框使用---第三方框架SSCheckBoxView-master
- iOS 开发之动画篇 - Transform和KeyFrame动画
- iOS 集合NSSet 用法详解
- ios开发--证书显示 此证书签发者无效 解决办法
- 超全!整理常用的iOS第三方资源
- 超全!整理常用的iOS第三方资源
- iOS开发证书显示“此证书的签发者无效”解决方法(相对完整版)/Missing iOS Distribution signing identity