我想通过红 - >绿 - >蓝,但是当我添加3种颜色,它只是经过最后两个颜色:
var duration = 6.0
UIView.animateKeyframesWithDuration(duration, delay: 1.0, options: UIViewKeyframeAnimationOptions.Repeat | UIViewKeyframeAnimationOptions.Autoreverse, animations: { () -> Void in
self.colorTransition.backgroundColor = UIColor.redColor()
self.colorTransition.backgroundColor = UIColor.greenColor()
self.colorTransition.backgroundColor = UIColor.blueColor()
}, completion: nil)
你必须调用addKeyframeWithRelativeStartTime
为三个转变,当他们开始并指定多久。
例如:
UIView.animateKeyframesWithDuration(duration, delay: 1.0, options: .Repeat | .Autoreverse, animations: {
UIView.addKeyframeWithRelativeStartTime(0, relativeDuration: 0.33) {
self.colorTransition.backgroundColor = UIColor.redColor()
}
UIView.addKeyframeWithRelativeStartTime(0.33, relativeDuration: 0.33) {
self.colorTransition.backgroundColor = UIColor.greenColor()
}
UIView.addKeyframeWithRelativeStartTime(0.66, relativeDuration: 0.34) {
self.colorTransition.backgroundColor = UIColor.blueColor()
}
}, completion: nil)