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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With