我可以使用CABasicAnimation旋转UIImageView,但我想知道在旋转时是否可以更改图像的颜色,所以它会转换为特定的颜色?
答案 0 :(得分:1)
是的,这是可能的。您可以向对象添加多个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")