示例代码是here。
将显式属性动画替换为隐式属性动画后,动画将中断。
显式动画:
-(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;
...
}为什么?
发布于 2012-02-09 23:32:10
当你使用隐式动画时,你不需要使用CATrasaction。请注意,uikit禁用了UIView根层layer的隐式动画
发布于 2011-07-07 20:35:58
您应该将CALayer的代理设置为不同的值,以便在适当的时间查看控制器视图( nitWithNibName:bundle:,awakeFromNib,viewDidLoad和viewWillAppear:animated),请查看此处:Does iPhone OS support implicit animation? 。
在我的机器上,一次触摸调用animate就能很好地工作。
https://stackoverflow.com/questions/6511504
复制相似问题