我正在尝试将 UIImageView
旋转 360 度,并查看了一些在线教程。如果 UIView
不停止或跳转到新位置,我无法让它们工作。
- 我怎样才能做到这一点?
我最近尝试的是:
[UIView animateWithDuration:1.0
delay:0.0
options:0
animations:^{
imageToMove.transform = CGAffineTransformMakeRotation(M_PI);
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];
但是如果我使用 2*pi,它根本不会移动(因为它是相同的位置)。如果我尝试只执行 pi(180 度),它会起作用,但如果我再次调用该方法,它会向后旋转。
编辑:
[UIView animateWithDuration:1.0
delay:0.0
options:0
animations:^{
[UIView setAnimationRepeatCount:HUGE_VALF];
[UIView setAnimationBeginsFromCurrentState:YES];
imageToMove.transform = CGAffineTransformMakeRotation(M_PI);
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];
也不行。它达到 180
度,暂停一秒钟,然后在再次开始之前重置回 0
度。
最佳答案
找到了一个非常适合我的方法(我稍微修改了一下):iphone UIImageView rotation
#import <QuartzCore/QuartzCore.h>
- (void) runSpinAnimationOnView:(UIView*)view duration:(CGFloat)duration rotations:(CGFloat)rotations repeat:(float)repeat {
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ];
rotationAnimation.duration = duration;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = repeat ? HUGE_VALF : 0;
[view.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}
关于ios - UIView无限360度旋转动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19194323/