2016-12-12 34 views
2

是否可以使用增強關鍵路徑(如here)針對Swift 3中的CATransform3D屬性和新的#keyPath關鍵字?帶#keyPath的CATransform3D關鍵路徑

換句話說東西來代替

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

let scaleAnimation = CABasicAnimation(keyPath: #keyPath(CALayer.transform.???)) 

回答

5

恕我直言CAValueFunction應使用,但對我來說不能很好地工作......

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

- >

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

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

- >

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

  • 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