[英]Frame property of CABasicAnimation is not animating?
在我的应用程序中,我尝试使用keyPath frame
添加以下动画,如下所示
CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"frame"];
animation.duration=0.6;
animation.repeatCount=1;
animation.delegate=self;
animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
animation.fromValue=[NSValue valueWithCGRect:self.layer.frame];
animation.toValue=[NSValue valueWithCGRect:rect];//rect is a new frame
[self.layer addAnimation:animation forKey:@"frameChange"];
[self setFrame:rect];
上面的方法没有实现动画,但是成功地使我得到了委托方法animationDidStop:(CAAnimation *)anim finished:
回调了。
但是下面的动画来定位属性运行良好
CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"position"];
animation.duration=0.6;
animation.repeatCount=1;
animation.delegate=self;
animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
animation.fromValue=[NSValue valueWithCGPoint:self.layer.position];
animation.toValue=[NSValue valueWithCGPoint:rect.origin];
[self.layer addAnimation:animation forKey:@"frameChange"];
为什么frame属性没有动画?
框架不是可设置动画的属性。 您必须为位置和范围制作一个动画。 要使它们都在一起,请将它们放置在CAAnimationGroup内。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.