是否可以使用增强型密钥路径(如here所述)对Swift 3中的CATransform3D属性使用新的#keyPath关键字?
换句话说,取代
let scaleAnimation = CABasicAnimation(keyPath: "transform.scale")
类似
let scaleAnimation = CABasicAnimation(keyPath: #keyPath(CALayer.transform.???))
答案 0 :(得分:10)
应该使用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