5

How to rotate UIImageView with two fingure touch in iOS SDK..as I know this is very simple but because of I am new in this technology so cant understand...

How to use UIRotationGestureRecognizer to implement this...

Please help me to solve this problem...

Thanks.

user1134979
  • 71
  • 1
  • 4
  • What have you done so far? Have you read this guide: http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers.html#//apple_ref/doc/uid/TP40009541-CH6-SW1 – bandejapaisa Jan 13 '12 at 15:56
  • you can refer following links, http://stackoverflow.com/questions/3448614/uiimageview-gestures-zoom-rotate-question, http://www.icodeblog.com/2010/10/14/working-with-uigesturerecognizers/ – rishi Jan 13 '12 at 16:52

1 Answers1

12

Code this on view did load or the imageview create function : m_ctrlImgVwShowImage - your's imageview

UIRotationGestureRecognizer *rotationRecognizer = [[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)] autorelease];
    [rotationRecognizer setDelegate:self];
    [m_ctrlImgVwShowImage addGestureRecognizer:rotationRecognizer];

//lastRotation is a cgfloat member variable

-(void)rotate:(id)sender {
    if([(UIRotationGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
        _lastRotation = 0.0;
        return;
    }

    CGFloat rotation = 0.0 - (_lastRotation - [(UIRotationGestureRecognizer*)sender rotation]);

    CGAffineTransform currentTransform = m_ctrlImgVwShowImage.transform;
    CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform,rotation);

    [m_ctrlImgVwShowImage setTransform:newTransform];

    _lastRotation = [(UIRotationGestureRecognizer*)sender rotation];
}
Perception
  • 79,279
  • 19
  • 185
  • 195
Vicky
  • 1,095
  • 16
  • 15