Bharath
Bharath

Reputation: 3031

Issue while using UIRotationGestureRecognizer to rotate Image?

I am trying to implement UIRotationGestureRecognizer for UIImageView.

UIRotationGestureRecognizer *rotateGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];

[self.view addGestureRecognizer:rotateGesture];

and in the selector method, I have dont this

-(void)rotate:(UIRotationGestureRecognizer *)gesture
{

    if ([gesture state] == UIGestureRecognizerStateBegan || [gesture state] == UIGestureRecognizerStateChanged) {
        selectedImage.transform=CGAffineTransformRotate(selectedImage.transform, gesture.rotation);

        [gesture setRotation:0];
    }

}

With the above code, image is rotating. But, the problem is, Image center is getting changed. with that, image rotating is looking bit Awkward.

Initial center for Image is (277,653) While rotating, value are getting increased till (365,659) and then again, it is coming back to (277,653).

What could be the reason? How to fix the center? How can I make my image to rotate at center of the UIImageView using UIRotationGestureRecognizer?

Upvotes: 2

Views: 2328

Answers (1)

Anil
Anil

Reputation: 2438

Try using

recognizer.rotation = 0;

Here's a tutorial. Hope it helps

Link

Upvotes: 4

Related Questions