如果您打算使用核心动画,那么方法将不同于您在前面的SO问题链接中演示的方法。相反,创建一个层,该层使用着色所需的颜色,然后为该层的不透明度设置动画。像这样:
CALayer *tintLayer = [CALayer layer];
// Center the layer on the view
[tintLayer setBounds:[imageView bounds]];
[tintLayer setPosition:CGPointMake([imageView bounds].size.width/2.0,
[imageView bounds].size.height/2.0)];
// Fill the color
[tintLayer setBackgroundColor:
[[UIColor colorWithRed:0.5 green:0.5 blue:0.0 alpha:1.0] CGColor]];
[tintLayer setOpacity:0.5];
[[imageView layer] addSublayer:tintLayer];
// Add the animation
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
[animation setFromValue:[NSNumber numberWithFloat:0.5]];
[animation setToValue:[NSNumber numberWithFloat:0.0]];
// Animate back to the starting value automatically
[animation setAutoreverses:YES];
// Animate over the course of 5 seconds.
[animation setDuration:5.0];
[tintLayer addAnimation:animation forKey:@"opacity"];
我唯一不确定的问题是,它是否也能正常工作,因为我们没有在染色层中指定混合模式。我将不得不看,看看什么混合是发生在默认与CA。
更新:找到
another SO
这篇文章说,在CA中混合取决于图层的“不透明”属性。