CABasicAnimation键

Mos*_*wad 10 iphone xcode objective-c ipad ios

我试图知道所用的所有密钥是什么 CABasicAnimation

像这个:

CABasicAnimation *imageRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
Run Code Online (Sandbox Code Playgroud)

旋转...我在哪里可以找到所有可能的键?并感谢前进

Mid*_* MP 21

以下是主要animationWithKeyPath价值观.

animationWithKeyPath

参考http://www.adamzucchi.com/blog/?p=24


the*_*ior 8

在对其中一个答案的评论中提到了此来源,但希望以后发现该问题的人可以接受此信息,有关此问题的正确列表是发布在Apple文档上的此页面:

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

这些链接中列出了以下关键路径:

(除非另有说明,否则CALayer属性使用默认的CABasicAnimation)

卡拉耶

  • anchorPointCGPoint
  • backgroundColorCGColor?
  • backgroundFilters[CIFilter]?(使用默认的CATransition,使用默认的CABasicAnimation对过滤器的子属性进行动画处理)
  • borderColorCGColor?
  • borderWidthCGFloat
  • 边界CGRect
  • compositingFilterCIFilter吗?(使用默认的CATransition,使用默认的CABasicAnimation对过滤器的子属性进行动画处理)
  • 内容CGImage?
  • contentsRectCGRect
  • cornerRadiusCGFloat
  • doubleSided布尔(无默认动画)
  • 过滤器:__ [CIFilter]?(使用默认的CATransition,使用默认的CABasicAnimation对过滤器的子属性进行动画处理)
  • 框架CGRect(!!不能动画!使用范围和位置)
  • 隐藏布尔
  • 面具CALayer?
  • masksToBounds布尔
  • 不透明度浮动(0 <=不透明度<= 1)
  • 位置CGPoint
  • shadowColorCGColor?
  • shadowOffsetCGSize(默认为(0,-3))
  • shadowOpacity浮动(0 <= shadowOpacity <= 1)
  • shadowPathCGPath?
  • shadowRadiusCGFloat(默认为3)
  • 子层[CALayer]?
  • sublayerTransformCATransform3D
  • 转换CATransform3D
  • 位置CGFloat

CALayer默认隐含CABasicAnimation **:持续时间 = 0.25s或当前事务的持续时间。
CALayer默认隐含的CATransition **:持续时间 = 0.25s或当前事务的持续时间,类型= kCATransitionFade,开始进度= 0,结束进度= 1

CIFilter(仅限macOS)

  • 名称字串
  • 启用布尔

CATransform3D

  • rotation.xNSNumber(弧度)
  • rotation.yNSNumber(弧度)
  • rotation.zNSNumber(弧度)
  • rotationNSNumber(弧度)(与rotation.z相同)
  • scale.xNSNumber
  • scale.yNSNumber
  • scale.zNSNumber
  • scaleNSNumber(所有三个比例因子的平均值)
  • translation.xNSNumber
  • translation.yNSNumber
  • translation.zNSNumber
  • 翻译NSValue含有NSSize或CGSize

CGPoint

  • xCGFloat
  • yCGFloat

CG尺寸

  • 宽度CGFloat
  • 高度CGFloat

CGRect

  • 来源CGPoint
  • origin.xCGFloat
  • 来源CGFloat
  • 尺寸CG 尺寸
  • size.widthCGFloat
  • size.heightCGFloat


Eug*_*ene 6

你可以简单地写: CABasicAnimation(keyPath: #keyPath(CAShapeLayer.strokeColor))

另外,使用 command+shift+o,打开,例如 CALayer.h 并观看评论。**Apple 团队提供有关动画功能的信息

对于动画键:

====漂亮的包装器;用法示例====

请回复这条关于不正确的消息,如果你会看到

extension CABasicAnimation {
        convenience init(_ key: CAPropertyAnimation.Key, duration: Double) {
        self.init(keyPath: key.keyPath)
        self.duration = duration
    }
}
Run Code Online (Sandbox Code Playgroud)

XCode 外观


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](/sf/ask/3096155751/)

     [Stack overflow 2](/sf/ask/973917101/)

     */

    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"
    }
}
Run Code Online (Sandbox Code Playgroud)