Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CABasicAnimation keys

I'm trying to know what are all the possible keys used in 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

like image 570
Mosab Alawad Avatar asked Dec 17 '12 11:12

Mosab Alawad


2 Answers

You may simply write: 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

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
    }
}

XCode look


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"
    }
}
like image 71
Eugene Avatar answered Oct 10 '22 02:10

Eugene


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.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

  • 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

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

CIFilter (macOS only)

  • name: String
  • enabled: Bool

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: NSValue containing an NSSize or CGSize

CGPoint

  • x: CGFloat
  • y: CGFloat

CGSize

  • width: CGFloat
  • height: CGFloat

CGRect

  • origin: CGPoint
  • origin.x: CGFloat
  • origin.y: CGFloat
  • size: CGSize
  • size.width: CGFloat
  • size.height: CGFloat
like image 25
thecodewarrior Avatar answered Oct 10 '22 02:10

thecodewarrior