我正在尝试以一定的间隔重复(360)旋转图像。我找到了这个答案(Image rotation in iOS),看起来不错,但对我不起作用。当我加载VC时,我可以看到轻微的移动,但仅此而已。有什么想法吗?我使用的代码如下:
- (void)viewDidAppear:(BOOL)animated {
[self.compass setTransform:CGAffineTransformMakeRotation(10*(M_PI/360))];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(rotation) userInfo:nil repeats:YES];
}
-(void)rotation{
[self.compass setTransform:CGAffineTransformMakeRotation(10*(M_PI/360))];
}编辑:
- (void)viewDidAppear:(BOOL)animated {
[self.compass setTransform:CGAffineTransformMakeRotation(10*(M_PI/360))];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(rotation) userInfo:nil repeats:YES];
}
-(void)rotation{
[self.compass setTransform:CGAffineTransformMakeRotation(10*(M_PI/360))];
CGAffineTransform transform = CGAffineTransformRotate(self.compass.transform, 10*(M_PI/360));
[self.compass setTransform:transform];
}发布于 2017-02-16 06:07:40
设置旋转动画,如下所示:
[UIView animateWithDuration:0.3 animations:^{
compas.transform = CGAffineTransformMakeRotation(M_PI/2);
}];发布于 2017-02-16 06:03:48
你的旋转正在发生,但它只是一个非常小的旋转: 10*pi/360弧度等于5度。Pi弧度等于180度,因此如果您想将其旋转360度,请旋转2 * M_PI。
但是请注意,您当前没有动画移动,并且当您只是旋转一个没有动画的视图时,它看起来与它的变换仍然是CGAffineTransformIdentity时完全一样。要使过渡具有动画效果,请查看UIView动画:https://www.raywenderlich.com/2454/uiview-tutorial-for-ios-how-to-use-uiview-animation
发布于 2017-02-16 06:03:57
您还需要添加之前的旋转,否则您将一次又一次地旋转到相同的角度:
CGAffineTransformMakeRotation(NewAngle + 10*(M_PI/360))https://stackoverflow.com/questions/42260761
复制相似问题