Ios CALayer显式动画
伙计们,我正试着按照 有一段代码:Ios CALayer显式动画,ios,objective-c,calayer,caanimation,Ios,Objective C,Calayer,Caanimation,伙计们,我正试着按照 有一段代码: CABasicAnimation* fadeAnim = [CABasicAnimation animationWithKeyPath:@"opacity"]; fadeAnim.fromValue = [NSNumber numberWithFloat:1.0]; fadeAnim.toValue = [NSNumber numberWithFloat:0.0]; fadeAnim.duration = 5.0; [theLayer addAnimation
CABasicAnimation* fadeAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeAnim.fromValue = [NSNumber numberWithFloat:1.0];
fadeAnim.toValue = [NSNumber numberWithFloat:0.0];
fadeAnim.duration = 5.0;
[theLayer addAnimation:fadeAnim forKey:@"opacity"];
// Change the actual data value in the layer to the final value.
theLayer.opacity = 0.0;
这说明我应该在最后更改一个属性。但它似乎工作不好(它会立即更改不透明度)-持续时间不是5(为了更好的可见性,我将其更改为5),因此动画不是CABasicAnimation,而是隐式的。
它只在我设置layer.opacity=0.0时起作用在我将动画添加到层
之前,请执行code>。我是做错了什么,还是文档中有bug?
P.S运行最新的XCode,iOS 7.1模拟器。
在添加动画之前更新模型层
CABasicAnimation*fadeAnim=[CABasicAnimation animationWithKeyPath:@“不透明”];
fadeAnim.fromValue=[NSNumber numberWithFloat:1.0];
fadeAnim.toValue=[NSNumber numberWithFloat:0.0];
fadeAnim.duration=5.0;
//将图层中的实际数据值更改为最终值。
图层不透明度=0.0;
[Layer addAnimation:fadeAnim forKey:@“不透明度”];
在执行动画之前更改属性,或者在动画结束后使用动画代理功能执行。Add fadeAnim.removedOnCompletion=否;和[fadeAnim setFillMode:kCAFillModeForwards];最终不透明度应在开始时设置。