我正在尝试使用计时器逐渐旋转UIImageView,此代码将其旋转,但它似乎并未围绕图像的中心旋转,以及将CGAffineTransformMakeRotation
添加到我的代码中似乎也停止了“主要”方法
#define radians(degrees) (degrees * M_PI/180)
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.016 target:self selector:@selector(main) userInfo:nil repeats:YES];
-(void)main{
rotate++;
uiImageView.transform = CGAffineTransformMakeRotation(radians(rotate));
uiImageView.center = CGPointMake(uiImageView.center.x+1, uiImageView.center.y);
}
最佳答案
试试这个 :
开始动画:
CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
rotation.fromValue = [NSNumber numberWithFloat:0];
rotation.toValue = [NSNumber numberWithFloat:(2*M_PI)];
rotation.duration = 1.0;// Speed
rotation.repeatCount = HUGE_VALF;// Repeat forever.
[imgViewCube.layer addAnimation:rotation forKey:@"Spin"];
停止动画:
[imgViewCube.layer removeAnimationForKey:@"Spin"];
关于ios - 使用计时器逐渐旋转UIImageView,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25521929/