在我的应用程序中,我尝试使用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属性不是动画?
答案 0 :(得分:3)
Frame不是可动画的属性。你必须为位置和边界制作动画。要将它们放在一起,将它们放在CAAnimationGroup中。