xcode CABasicAnimation 键
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13913101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CABasicAnimation keys
提问by Mosab Alawad
I'm trying to know what are all the possible keys used in CABasicAnimation
我想知道所有可能使用的键是什么 CABasicAnimation
like this one:
像这个:
CABasicAnimation *imageRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
which makes a rotation ... where can I find all possible keys? and thanks in forward
这使得旋转......我在哪里可以找到所有可能的键?并感谢转发
采纳答案by Johann Dirdal
Have you considered looking up the class reference for CABasicAnimation, and its corresponding super classes?
您是否考虑过查找 CABasicAnimation 及其对应的超类的类参考?
CABasicAnimation: https://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CABasicAnimation_class/Introduction/Introduction.html
CABasicAnimation:https: //developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CABasicAnimation_class/Introduction/Introduction.html
CAPropertyAnimation https://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CAPropertyAnimation_class/Introduction/Introduction.html#//apple_ref/occ/cl/CAPropertyAnimation
CAPropertyAnimation https://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CAPropertyAnimation_class/Introduction/Introduction.html#//apple_ref/occ/cl/CAPropertyAnimation
回答by Midhun MP
The following is the major animationWithKeyPath
values.
以下是主要animationWithKeyPath
值。
Reference http://www.adamzucchi.com/blog/?p=24
回答by thecodewarrior
This source is mentioned in a comment on one of the answers, but in the hope that this can be accepted for those in the future who find this question, the correct list as of the date this is posted is this page on apple's docs:
在对其中一个答案的评论中提到了此来源,但希望将来发现此问题的人可以接受这一点,截至发布之日的正确列表是苹果文档上的此页面:
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreAnimation_guide/AnimatableProperties/AnimatableProperties.htmlhttps://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreAnimation_guide/Key-ValueCodingExtensions/Key-ValueCodingExtensions.html
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreAnimation_guide/AnimatableProperties/AnimatableProperties.html https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreAnimation_guide/Key -ValueCodingExtensions/Key-ValueCodingExtensions.html
Here are the keypaths listed in those links:
以下是这些链接中列出的关键路径:
(Unless otherwise noted, CALayer properties use the default CABasicAnimation)
(除非另有说明,CALayer 属性使用默认的 CABasicAnimation)
CALayer
图层
- anchorPoint: CGPoint
- backgroundColor: CGColor?
- backgroundFilters: [CIFilter]?(uses default CATransition, sub-properties of filters are animated using default CABasicAnimation)
- borderColor: CGColor?
- borderWidth: CGFloat
- bounds: CGRect
- compositingFilter: CIFilter?(uses default CATransition, sub-properties of filters are animated using default CABasicAnimation)
- contents: CGImage?
- contentsRect: CGRect
- cornerRadius: CGFloat
- doubleSided: Bool(no default animation)
- filters: __[CIFilter]? (uses default CATransition, sub-properties of filters are animated using default CABasicAnimation)
- frame: CGRect(!!not animatable!! use bounds and position)
- hidden: Bool
- mask: CALayer?
- masksToBounds: Bool
- opacity: Float(0 <= opacity <= 1)
- position: CGPoint
- shadowColor: CGColor?
- shadowOffset: CGSize(default is (0,-3))
- shadowOpacity: Float(0 <= shadowOpacity <= 1)
- shadowPath: CGPath?
- shadowRadius: CGFloat(default is 3)
- sublayers: [CALayer]?
- sublayerTransform: CATransform3D
- transform: CATransform3D
- zPosition: CGFloat
- 锚点:CGPoint
- 背景颜色:CGColor?
- 背景过滤器:[CIFilter]?(使用默认 CATransition,过滤器的子属性使用默认 CABasicAnimation 进行动画处理)
- BORDERCOLOR:CGColor?
- 边框宽度:CGFloat
- 边界:CGRect
- 合成过滤器:CIFilter?(使用默认 CATransition,过滤器的子属性使用默认 CABasicAnimation 进行动画处理)
- 内容:CGImage?
- 内容矩形:CGRect
- 角半径:CGFloat
- doubleSided: Bool(无默认动画)
- 过滤器:__[CIFilter]?(使用默认 CATransition,过滤器的子属性使用默认 CABasicAnimation 进行动画处理)
- frame: CGRect(!!不可动画!!使用边界和位置)
- 隐藏:布尔
- 面具:CALayer?
- maskToBounds: Bool
- 不透明度:浮动(0 <= 不透明度 <= 1)
- 位置: CGPoint
- 则shadowColor:CGColor?
- shadowOffset: CGSize(默认是 (0,-3))
- shadowOpacity: Float(0 <= shadowOpacity <= 1)
- 阴影路径:CGPath?
- shadowRadius: CGFloat(默认为 3)
- 子层:[CALayer]?
- sublayerTransform: CATransform3D
- 变换:CATransform3D
- zPosition: CGFloat
CALayer default implied CABasicAnimation**: duration= 0.25s or duration of current transaction.
CALayer default implied CATransition**: duration= 0.25s or duration of current transaction, type = kCATransitionFade, start progress = 0, end progress = 1
CALayer 默认隐含 CABasicAnimation**:duration= 0.25s 或当前事务的持续时间。
CALayer 默认隐含 CATransition**:duration= 0.25s 或当前事务的持续时间,类型 = kCATransitionFade,开始进度 = 0,结束进度 = 1
CIFilter (macOS only)
CIFilter(仅限 macOS)
- name: String
- enabled: Bool
- 名称:字符串
- 启用:布尔
CATransform3D
CATransform3D
- rotation.x: NSNumber(radians)
- rotation.y: NSNumber(radians)
- rotation.z: NSNumber(radians)
- rotation: NSNumber(radians) (identical to rotation.z)
- scale.x: NSNumber
- scale.y: NSNumber
- scale.z: NSNumber
- scale: NSNumber(average of all three scale factors)
- translation.x: NSNumber
- translation.y: NSNumber
- translation.z: NSNumber
- translation: NSValuecontaining an NSSize or CGSize
- rotation.x: NSNumber(弧度)
- rotation.y: NSNumber(弧度)
- rotation.z: NSNumber(弧度)
- 旋转:NSNumber(弧度)(与rotation.z相同)
- scale.x: NSNumber
- scale.y: NSNumber
- scale.z: NSNumber
- scale: NSNumber(所有三个比例因子的平均值)
- 翻译.x: NSNumber
- 翻译.y: NSNumber
- 翻译.z: NSNumber
- 翻译:NSValue含有NSSize或CGSize
CGPoint
CG点
- x: CGFloat
- y: CGFloat
- x: CGFloat
- y: CGFloat
CGSize
CG尺寸
- width: CGFloat
- height: CGFloat
- 宽度:CGFloat
- 高度:CGFloat
CGRect
CG矩形
- origin: CGPoint
- origin.x: CGFloat
- origin.y: CGFloat
- size: CGSize
- size.width: CGFloat
- size.height: CGFloat
- 来源:CGPoint
- origin.x: CGFloat
- origin.y: CGFloat
- 尺寸:CG尺寸
- size.width: CGFloat
- 尺寸.高度:CGFloat
回答by Eugene
You may simplywrite: CABasicAnimation(keyPath: #keyPath(CAShapeLayer.strokeColor))
你可以简单地写: CABasicAnimation(keyPath: #keyPath(CAShapeLayer.strokeColor))
Also, use command+shift+o, open, for example, CALayer.h and watch a comments. **Apple team provides information about animatable feature
另外,使用 command+shift+o,打开,例如 CALayer.h 并观看评论。**Apple 团队提供有关动画功能的信息
for animatable keys:
对于动画键:
==== Pretty Wrapper; Usage example====
====漂亮的包装器;用法示例====
Please reply this message about incorrectness, if u'll see
请回复这条关于不正确的消息,如果你会看到
extension CABasicAnimation {
convenience init(_ key: CAPropertyAnimation.Key, duration: Double) {
self.init(keyPath: key.keyPath)
self.duration = duration
}
}
extension CAPropertyAnimation {
enum Key {
/// `CALayer` in the `Parent` layer for `Subclass layers`. Able to use this keys for animating `Subclass layers`
case caLayer(_ property: CALayer.CALayerAnimatableProperty)
case shapeLayer(_ property: CAShapeLayer.AnimatableProperty)
case emitterLayer(_ property: CAEmitterLayer.AnimatableProperty)
case gradientLayer(_ property: CAGradientLayer.AnimatableProperty)
case replicationLayer(_ property: CAReplicatorLayer.AnimatableProperty)
case textLayer(_ property: CATextLayer.AnimatableProperty)
var keyPath: String {
switch self {
case .caLayer(let property): return property.rawValue
case .shapeLayer(let property): return property.rawValue
case .emitterLayer(let property): return property.rawValue
case .gradientLayer(let property): return property.rawValue
case .replicationLayer(let property): return property.rawValue
case .textLayer(let property): return property.rawValue
}
}
}
}
extension CALayer {
/**
- references:
[Apple. Key-Value Coding Extensions (CALayer examples)](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CoreAnimation_guide/Key-ValueCodingExtensions/Key-ValueCodingExtensions.html#//apple_ref/doc/uid/TP40004514-CH12-SW2)
[Apple. Animatable Properties.](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CoreAnimation_guide/AnimatableProperties/AnimatableProperties.html)
[Stack overflow 1](https://stackoverflow.com/questions/44230796/what-is-the-full-keypath-list-for-cabasicanimation)
[Stack overflow 2](https://stackoverflow.com/questions/13913101/cabasicanimation-keys)
*/
enum CALayerAnimatableProperty: String {
/// CGPoint
case anchorPoint = "anchorPoint"
/// CGPoint
case anchorPointZ = "anchorPointZ"
/// CGColor?
case backgroundColor = "backgroundColor"
/// [CIFilter]? (uses default CATransition, sub-properties of filters are animated using default CABasicAnimation)
case backgroundFilters = "backgroundFilters"
/// CGColor?
case borderColor = "borderColor"
/// CGFloat
case borderWidth = "borderWidth"
/// CGRect
case bounds = "bounds"
/// CGpoint
case boundsOrigin = "bounds.origin"
/// CGFloat
case boundsOriginX = "bounds.origin.x"
/// CGFloat
case boundsOriginY = "bounds.origin.y"
/// CGSize
case boundsSize = "bounds.size"
/// CGFloat
case boundsWidth = "bounds.size.width"
/// CGFloat
case boundsHeight = "bounds.size.height"
/// CIFilter? (uses default CATransition, sub-properties of filters are animated using default CABasicAnimation)
case compositingFilter = "compositingFilter"
/// typically a CGImageRef, but may be something else
case contents = "contents"
/// CGRect
case contentsRect = "contentsRect"
/// CGFloat
case contentsScale = "contentsScale"
/// CGRect
case contentsCenter = "contentsCenter"
/// CGFloat
case cornerRadius = "cornerRadius"
/// Bool (no default animation)
case doubleSided = "doubleSided"
/// [CIFilter]? (uses default CATransition, sub-properties of filters are animated using default CABasicAnimation)
case filters = "filters"
/// CGRect (!!not animatable!! use bounds and position)
case frame = "frame"
/// Bool
case hidden = "hidden"
/// Bool
case masksToBounds = "masksToBounds"
/// Float
case minificationFilterBias = "minificationFilterBias"
/// Float (0 <= opacity <= 1)
case opacity = "opacity"
/// CGPoint
case position = "position"
/// CGFloat
case positionX = "position.x"
/// CGFloat
case positionY = "position.y"
/// CGFloat
case rotationX = "transform.rotation.x"
/// CGFloat
case rotationY = "transform.rotation.y"
/// CGFloat
case rotationZ = "transform.rotation.z"
/// CGFloat
case scale = "transform.scale"
/// CGFloat
case scaleX = "transform.scale.x"
/// CGFloat
case scaleY = "transform.scale.y"
/// CGFloat
case scaleZ = "transform.scale.z"
/// CGColor?
case shadowColor = "shadowColor"
/// CGSize (default is (0,-3))
case shadowOffset = "shadowOffset"
/// Float (0 <= shadowOpacity <= 1); default is 0
case shadowOpacity = "shadowOpacity"
/// CGpath?
case shadowPath = "shadowPath"
/// CGFloat (default is 3)
case shadowRadius = "shadowRadius"
/// [CALayer]?
case sublayers = "sublayers"
/// Bool
case shouldRasterize = "shouldRasterize"
/// CGFloat
case rasterizationScale = "rasterizationScale"
/// CATransform3D
case sublayerTransform = "sublayerTransform"
/// CGSize
case translation = "transform.translation"
/// CGFloat
case translationX = "transform.translation.x"
/// CGFloat
case translationY = "transform.translation.y"
/// CGFloat
case translationZ = "transform.translation.z"
/// CATransform3D
case transform = "transform"
/// CGFloat
case zPosition = "zPosition"
}
}
extension CAShapeLayer {
enum AnimatableProperty: String {
/// CGColor?
case fillColor = "fillColor"
/// [NSNumber]?
case lineDashPhase = "lineDashPhase"
/// CGFloat
case lineWidth = "lineWidth"
/// CGFloat
case miterLimit = "miterLimit"
/// CGColor?
case strokeColor = "strokeColor"
/// CGFloat
case strokeStart = "strokeStart"
/// CGFloat
case strokeEnd = "strokeEnd"
}
}
extension CAEmitterLayer {
enum AnimatableProperty: String {
/// CGPoint
case emitterPosition = "emitterPosition"
/// CGFloat
case emitterZPosition = "emitterZPosition"
/// CGSize
case emitterSize = "emitterSize"
}
}
extension CAGradientLayer {
enum AnimatableProperty: String {
/// [CGColor]? ([Any]? by Apple docs, but CGColor works as well)
case colors = "colors"
/// [NSNuber]?
case locations = "locations"
/// CGPoint
case endPoint = "endPoint"
/// CGPoint
case startPoint = "startPoint"
}
}
extension CAReplicatorLayer {
enum AnimatableProperty: String {
/// CFTimeInterval (Double)
case instanceDelay = "instanceDelay"
/// CATransform3D
case instanceTransform = "instanceTransform"
/// Float
case instanceRedOffset = "instanceRedOffset"
/// Float
case instanceGreenOffset = "instanceGreenOffset"
/// Float
case instanceBlueOffset = "instanceBlueOffset"
/// Float
case instanceAlphaOffset = "instanceAlphaOffset"
}
}
extension CATextLayer {
enum AnimatableProperty: String {
/// CGSize
case fontSize = "fontSize"
/// CGColor?
case foregroundColor = "foregroundColor"
}
}
回答by Vladimir
You can find them in "Key Path Support for Structure Fields"section of CoreAnimation programming guide
您可以在CoreAnimation 编程指南的“结构字段的关键路径支持”部分找到它们
回答by IluTov
You can basically use every possible keyPath. So if an object implements the property 'alpha', like all views do, you can let this property animate automatically.
您基本上可以使用所有可能的keyPath。所以如果一个对象实现了属性“alpha”,就像所有视图一样,你可以让这个属性自动动画。
The CAAnimation then calculates steps between the start point, and the end point of the animation, sets them and redraws the view.
CAAnimation 然后计算动画的起点和终点之间的步骤,设置它们并重绘视图。