Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CATransform3D Key Paths with #keyPath

Is it possible to use enhanced key path (as described here) for a CATransform3D property in Swift 3 with new #keyPath keyword?

In other words to replace

let scaleAnimation = CABasicAnimation(keyPath: "transform.scale")

with something like

let scaleAnimation = CABasicAnimation(keyPath:  #keyPath(CALayer.transform.???))
like image 864
Radek Avatar asked Dec 12 '16 13:12

Radek


1 Answers

CAValueFunction should be used.

let scaleAnimation = CABasicAnimation(keyPath: "transform.scale")

->

let scaleAnimation = CABasicAnimation(keyPath: #keyPath(CALayer.transform))
scaleAnimation.valueFunction = CAValueFunction(name: kCAValueFunctionScale)

and

let rotationAnimation = CABasicAnimation(keyPath: "transform.rotation")

->

let rotationAnimation = CABasicAnimation(keyPath: #keyPath(CALayer.transform))
rotationAnimation.valueFunction = CAValueFunction(name: kCAValueFunctionRotateZ)

etc.

  • rotation.x -> kCAValueFunctionRotateX
  • rotation.y -> kCAValueFunctionRotateY
  • rotation.z -> kCAValueFunctionRotateZ
  • rotation -> kCAValueFunctionRotateZ
  • scale.x -> kCAValueFunctionScaleX
  • scale.y -> kCAValueFunctionScaleY
  • scale.z -> kCAValueFunctionScaleZ
  • scale -> kCAValueFunctionScale
  • translation.x -> kCAValueFunctionTranslateX
  • translation.y -> kCAValueFunctionTranslateY
  • translation.z -> kCAValueFunctionTranslateZ
  • translation -> kCAValueFunctionTranslate
like image 87
JMI Avatar answered Oct 01 '22 00:10

JMI