【发布时间】:2015-07-07 18:11:50
【问题描述】:
我可以使用 CABasicAnimation 旋转 UIImageView,但我想知道是否可以在图像旋转时更改图像的颜色,以便它转换为特定颜色?
【问题讨论】:
标签: objective-c cabasicanimation
我可以使用 CABasicAnimation 旋转 UIImageView,但我想知道是否可以在图像旋转时更改图像的颜色,以便它转换为特定颜色?
【问题讨论】:
标签: objective-c cabasicanimation
是的,这是可能的。您可以将多个 CA 动画添加到一个对象。您还可以将它们放在一个组中,并作为一个组来控制时序和其他参数。
例如:
// make animation group
let myAnimations = CAAnimationGroup()
myAnimations.duration = 1
myAnimations.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
// make opacity animation
let opacity = CABasicAnimation(keyPath: "opacity")
opacity.fromValue = 0
opacity.toValue = 100
// make a bg color animation
let color = CABasicAnimation(keyPath: "backgroundColor")
color.fromValue = UIColor.redColor().CGColor
color.toValue = UIColor.blueColor().CGColor
// make position animation
let position = CABasicAnimation(keyPath: "position.y")
position.fromValue = 0
position.toValue = contentView.center.y - 80
// add the animations to the group
myAnimations.animations = [opacity, position, color]
// add the group to the layer
myObject.layer.addAnimation(placeAnimation, forKey: "myAnimations")
【讨论】: