Tigran Tigran - 2 years ago 266
Swift Question

The values of convenience initializer init(keyPath:) for CABasicAnimation

I'm using CABasicAnimation for layer animations. In convenience initializer init(keyPath:) I specify which values I want to animate, but I do it mostly intuitively. I mean, I know that it should animate layer's position.x, for example, so I use that value. But where can I find the complete list of values? I checked the documentation for both the initializer and CABasicAnimation and found just some examples of values.

Answer Source

The resource you are looking for is the Key-Value Coding Extensions page of the Core Animation Programming Guide.

There are additions for properties of the types CGPoint, CGSize, CGRect, and CATransform3D.


CGPoint

For point properties you can use .x and .y. For example:

"position.x" // use a number

CGSize

For size properties you can use .width and .height. For example:

"shadowOffset.height" // use a number

CGRect

For rectangle properties you can use origin and size, as well as the point and size additions on those. For example:

"bounds.origin.x"  // use a number
"frame.size.width" // use a number
"frame.origin"     // use a point

CATransform3D

Core Animation transform properties have additions for scale (.x, .y, .z), rotation (.x, .y, .z), and translation (.x, .y, .z). For example:

"transform.rotation.z"    // use a number
"transform.translation.x" // use a number

You can also just use .scale as a number that scales uniformly on all axis, .rotation as a number for the rotation around the z-axis (same as rotation.z), and .translation as a size that translates along the x- and y-axis.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download