Image rotation in iOS

2019-07-24 05:28发布

问题:

I want to rotate an image by 360 degree delay for 2 or 3 seconds again rotate it by 360 degree and the process should continue on. Any possible suggestions for the same ? Actually tried Cgaffinetransfom but its not working for 360 degree .

回答1:

You can rotate your image like this:

[YourImageView setTransform:CGAffineTransformMakeRotation(10*(M_PI/360))];

Now to perform it continuous you need to set the timer like this:

[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(doRotateImage) userInfo:nil repeats:YES];

Rotate function:

-(void)doRotateImage{
    [YourImageView setTransform:CGAffineTransformMakeRotation(10*(M_PI/360))];
}

Thats it.



回答2:

You could try this method:

- (void)rotateImageView{
[UIView animateWithDuration:0.4f delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
    [yourImageView setTransform:CGAffineTransformRotate(yourImageView.transform, M_PI_2)];
}completion:^(BOOL finished){
    if (finished) {
        [self rotateImageView];
    }
}];
}