Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 714
user1134979 Avatar asked Jan 13 '12 15:01

user1134979


1 Answers

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];
}
like image 84
Vicky Avatar answered Nov 10 '22 18:11

Vicky