gpt4 book ai didi

ios - UIView无限360度旋转动画?

转载 作者:IT老高 更新时间:2023-10-28 12:14:16 26 4
gpt4 key购买 nike

我正在尝试将 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/9844925/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com