隐式属性动画不适用于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是否支持隐式动画? 。
在我的机器上调用触摸动画非常好。
- NSBundle – (尚未加载)错误
- 保存录制的video太长时,应用程序崩溃
- 当用户使用iOS Swift轻击推送通知时,在特定视图中打开应用程序
- 在以编程方式创build视图时,我应该在哪里设置自动布局约束
- TestFlight中的最大testing人员
- 在webview或MPMoviePlayerViewController的iOSstreamvideo
- 加速框架FFT vDSPztoc拆分实数forms以分割实数向量
- 如何实现UICollectionView的委托和数据源方法,当它在iOS中的自定义TableViewCell中时,目标C
- UItableView用UIButton替代选中标记或用于多选的自定义CheckImage