IOS CABasicAniamtion keypath:frame无效
写出如上方法并未出现任何动画效果。
CABasicAniamtion是关键帧动画,操作的是layer层,而frame是view层的属性值。要使用CABasicAniamtion做视图的frame变化,你可以通过bounds和position来操作,如:
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"];
你做关键帧动画,要首先看下view和layer的区别,其动画实现所操作的层次是不一样的
这一句也不够啊。。。比如旋转的话
CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
basicAnimation.fromValue = [NSNumber numberWithInt:0];
basicAnimation.toValue = [NSNumber numberWithInt:M_PI*100];
[basicAnimation setDuration:200];
[basicAnimation setRepeatCount:NSIntegerMax];
[basicAnimation setAutoreverses:YES];
[self.view.layer addAnimation:basicAnimation forKey:@"rotation"];