我正在嘗試使用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