到目前为止,我有这个。我希望图像旋转约30秒然后停下来然后面向另一个方向。
修改。更改了代码。我有这个,但它旋转,并没有停止180度。我希望它旋转几次然后停在相反的方向。
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.duration = 0.60;//animation.duration = 0.60;
animation.repeatCount = 1;//animation.repeatCount = 1000ˆ
//#warning remove comment brackets below
animation.keyTimes = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:1.0], nil];
animation.values = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:(degrees / 180)*M_PI], nil];
animation.fillMode = kCAFillModeForwards;
如何在图像仍然旋转180度的情况下停止动画。
答案 0 :(得分:0)
怎么样
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
animation.delegate = self;
animation.autoreverses = YES;
animation.repeatDuration = 30;
animation.duration = 1.0;
animation.fromValue = [NSNumber numberWithFloat:-degreeToRadian(180)];
animation.toValue=[NSNumber numberWithFloat:degreeToRadian(180)];
[self.button.layer addAnimation:animation forKey:@"animation"];
然后添加委托方法
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
self.button.transform = CGAffineTransformMakeRotation(degreeToRadian(180));
}
我希望这就是你想要的。