隐式属性动画不适用于CAReplicatorLayer?

示例代码在这里 。

使用隐式属性动画替换显式属性动画后,动画将被破坏。

显式动画:

-(void)animate:(id)sender { ... //Transform Animation animation = [CABasicAnimation animationWithKeyPath:@"transform"]; animation.fromValue = [NSValue valueWithCATransform3D: CATransform3DIdentity]; animation.toValue = [NSValue valueWithCATransform3D: t]; animation.duration = 1.0; animation.removedOnCompletion = NO; animation.fillMode = kCAFillModeBoth; [subLayer addAnimation:animation forKey:@"transform"]; //Opacity Animation animation = [CABasicAnimation animationWithKeyPath:@"opacity"]; animation.fromValue = [NSNumber numberWithFloat:1.0]; animation.toValue = [NSNumber numberWithFloat:0.0]; animation.duration = 1.0; animation.removedOnCompletion = NO; animation.fillMode = kCAFillModeBoth; [subLayer addAnimation:animation forKey:@"opacity"]; ... } -(void)reset:(id)sender { ... //Transform Animation animation = [CABasicAnimation animationWithKeyPath:@"transform"]; animation.fromValue = [NSValue valueWithCATransform3D: t]; animation.toValue = [NSValue valueWithCATransform3D: CATransform3DIdentity]; animation.duration = 1.0; animation.removedOnCompletion = NO; animation.fillMode = kCAFillModeBoth; [subLayer addAnimation:animation forKey:@"transform"]; //Opacity Animation animation = [CABasicAnimation animationWithKeyPath:@"opacity"]; animation.fromValue = [NSNumber numberWithFloat:0.0]; animation.toValue = [NSNumber numberWithFloat:1.0]; animation.duration = 1.0; animation.removedOnCompletion = NO; animation.fillMode = kCAFillModeBoth; [subLayer addAnimation:animation forKey:@"opacity"]; ... } 

隐式动画:

 -(void)animate:(id)sender { ... //Transform Animation [CATransaction setAnimationDuration:1]; subLayer.transform = t; //Opacity Animation [CATransaction setAnimationDuration:1]; subLayer.opacity = 0; ... } -(void)reset:(id)sender { ... //Transform Animation [CATransaction setAnimationDuration:1]; subLayer.transform = CATransform3DIdentity; //Opacity Animation [CATransaction setAnimationDuration:1]; subLayer.opacity = 1; ... } 

为什么?

使用隐式动画时,不需要使用CATrasaction。 小心uikit禁用层的隐式动画,这是UIView的根层

您应该将CALayer的委托设置为视图控制器在适当的时间查看的不同内容(不包括nitWithNibName:bundle:,awakeFromNib,viewDidLoad和viewWillAppear:animated),请看这里: iPhone OS是否支持隐式动画? 。

在我的机器上调用触摸动画非常好。