本文介绍了隐式属性动画不适用于CAReplicatorLayer吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例代码位于。 / p>
用隐式属性动画替换显式属性动画后,该动画将被破坏。
显式动画:
-(void)animate:(id)sender {
...
//变换动画
动画= [CABasicAnimation animationWithKeyPath:@ transform];
animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
animation.toValue = [NSValue valueWithCATransform3D:t];
animation.duration = 1.0;
animation.removedOnCompletion =否;
animation.fillMode = kCAFillModeBoth;
[subLayer addAnimation:animation forKey:@ transform];
//不透明度动画
animation = [CABasicAnimation animationWithKeyPath:@ opacity];
animation.fromValue = [NSNumber numberWithFloat:1.0];
animation.toValue = [NSNumber numberWithFloat:0.0];
animation.duration = 1.0;
animation.removedOnCompletion =否;
animation.fillMode = kCAFillModeBoth;
[subLayer addAnimation:animation forKey:@ opacity];
...
}
-(void)reset:(id)sender {
...
//变换动画
animation = [CABasicAnimation animationWithKeyPath:@ transform];
animation.fromValue = [NSValue valueWithCATransform3D:t];
animation.toValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
animation.duration = 1.0;
animation.removedOnCompletion =否;
animation.fillMode = kCAFillModeBoth;
[subLayer addAnimation:animation forKey:@ transform];
//不透明度动画
animation = [CABasicAnimation animationWithKeyPath:@ opacity];
animation.fromValue = [NSNumber numberWithFloat:0.0];
animation.toValue = [NSNumber numberWithFloat:1.0];
animation.duration = 1.0;
animation.removedOnCompletion =否;
animation.fillMode = kCAFillModeBoth;
[subLayer addAnimation:animation forKey:@ opacity];
...
}
模仿动画:
-(void)animate:(id)sender {
...
//变换动画
[CATransaction setAnimationDuration:1];
subLayer.transform = t;
//不透明度动画
[CATransaction setAnimationDuration:1];
subLayer.opacity = 0;
...
}
-(void)reset:(id)sender {
...
//变换动画
[CATransaction setAnimationDuration:1];
subLayer.transform = CATransform3DIdentity;
//不透明度动画
[CATransaction setAnimationDuration:1];
subLayer.opacity = 1;
...
}
为什么?
解决方案
u使用隐式动画时不需要使用CATrasaction。
注意uikit禁用层的隐式动画,该层是UIView的根层
The sample code is here.
After replacing explicit property animations with implicit property animations, the animation is broken.
Explicit animation:
-(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"];
...
}
Implicit animation:
-(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;
...
}
Why?
解决方案
u don't need to use CATrasaction when you use implicit animation.be carefull that uikit disables the implicit animation of layer which is a root layer of UIView
这篇关于隐式属性动画不适用于CAReplicatorLayer吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!