user1134979
user1134979

Reputation: 71

UIRotationGestureRecognizer on UIImageview

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.

Upvotes: 5

Views: 4401

Answers (1)

Vicky
Vicky

Reputation: 1095

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];
}

Upvotes: 12

Related Questions