Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset UIImageView transform property

Tags:

iphone

ipad

In my project i am doing following activity on UIImageView 1.) rotate it 2.) move it 3.) zoom it. My project also has a button named as "New" which will reset all settings of app.my problem is that if i have rotate the image and click on new button,setting of UIImageVIew is not change. can some one has any idea.Thanks in advance

-(void)rotate:(id)sender {

    if([(UIRotationGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {

        lastRotation = 0.0;
        return;
    }

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

    CGAffineTransform oldTransform = [(UIPinchGestureRecognizer*)sender view].transform;
    CGAffineTransform newTransform = CGAffineTransformRotate(oldTransform,rotation);

    [[(UIRotationGestureRecognizer*)sender view] setTransform:newTransform];

    lastRotation = [(UIRotationGestureRecognizer*)sender rotation];
}

above code i am using for rotation.

like image 575
Rahul Avatar asked Jul 16 '11 07:07

Rahul


1 Answers

If imageView is your UIImageView object, resetting the transform property is done using,

imageView.transform = CGAffineTransformIdentity;

Additionally, you can shorten the rotate: method a bit if you are not using lastRotation anywhere else.

-(void)rotate:(UIRotationGestureRecognizer *)gesture {
    UIView * view = gesture.view;
    view.transform = CGAffineTransformRotate(view.transform, gesture.rotation);
    gesture.rotation = 0;
}
like image 167
Deepak Danduprolu Avatar answered Oct 22 '22 07:10

Deepak Danduprolu