0

I have implemented a rotation gesture for UIImageView.

Here is the Code that I implemented:

- (IBAction)rotaehandler:(UIRotationGestureRecognizer *)sender
{
    sender.view.transform = CGAffineTransformRotate(sender.view.transform, sender.rotation);
}

I connected UIRotationGestureRecognizer to UIImageView. It works but, How can i rotate image form its center.

Shabeer Ali
  • 903
  • 11
  • 20
  • 2
    Enter the concept of ["division"](http://en.wikipedia.org/wiki/Division_(mathematics)). –  Feb 05 '13 at 07:32
  • 2
    @ShaaberAli If you read the Wikipedia article I linked to, you'll see this basic mathematical operation explained pretty well. –  Feb 05 '13 at 07:35
  • `CGAffineTransformRotate(sender.view.transform, sender.rotation / SOME_CONSTANT)` –  Feb 05 '13 at 07:53

2 Answers2

1
CGFloat initialRotation = atan2f(sender.view.transform.b-somefloat, sender.view.transform.a-somefloat);

 CGFloat newRotation = initialRotation + sender.rotation;

 sender.view.transform = CGAffineTransformMakeRotation(newRotation);

try above code

Maniganda saravanan
  • 2,188
  • 1
  • 19
  • 35
BhushanVU
  • 3,455
  • 1
  • 24
  • 33
-1

Try this :

- (IBAction)rotaehandler:(UIRotationGestureRecognizer *)sender
    {


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

             NSLog(@"Rotate : %f",[gestureRecognizer rotation]);
             [sender setRotation:0];
         }
    }
Satish Azad
  • 2,302
  • 1
  • 16
  • 35
  • Please check http://stackoverflow.com/questions/11104042/how-to-get-a-rotated-zoomed-and-panned-image-from-an-uiimageview-at-its-full-re this will helps u – Satish Azad Feb 05 '13 at 10:26