我正在尝试使用CAKeyFrameAnimation为CALayer的backgroundColor创建动画。 当我用它的古典色彩它的作品;但是从patternImage UIColor(patternImage:"imageName").CGColor
生成的颜色完全不起作用。CAKeyFrameAnimation with colorImageImage
@IBAction func animFirstView(sender: AnyObject)
{
addAnim(view1, colors: [UIColor.blackColor().CGColor, UIColor.redColor().CGColor]) // THAT WORKS
}
@IBAction func animSecondView(sender: AnyObject)
{
var firstColor = UIColor(patternImage: UIImage(named:"stars1")!).CGColor;
addAnim(view2,
colors: [firstColor]); // THAT doesn't works at all :(
}
func addAnim(view:UIView, colors:[CGColor])
{
let anim = CAKeyframeAnimation(keyPath:"backgroundColor")
anim.values = colors;
anim.keyTimes = [0.0, 0.25, 0.5, 0.75, 1];
anim.calculationMode = kCAAnimationDiscrete
anim.duration = 0.3;
anim.repeatCount = Float.infinity;
view.layer.addAnimation(anim, forKey: "backgroundColor");
}
有人有想法吗?
是不是可以这样做还是我做错了什么?
的“错误” https://github.com/lastMove/patternBugDemo
感谢您在github上发布示例!这给了我一些工作。 – matt