Reputation: 514
I have the following code that allows a user to rotate an image on screen by pressing a button.
self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, rotationAmount);
This image is sitting inside of a UIScrollView which enables a user to zoom in on the photo. The problem is that when a user zooms the transform is reset. I can store the value of the transform and then re apply it after zooming but the image appears as though it is bouncing between the rotated version and non rotated version.
Is there a way to maintain the transform during zoom?
Here is the code for the scrollview
self.scrollView.minimumZoomScale=1.0;
self.scrollView.maximumZoomScale=6.0;
self.scrollView.contentSize=CGSizeMake(screenHeight, screenWidth-toolBarHeight);
self.scrollView.delegate=self;
[_scrollView setContentMode:UIViewContentModeScaleAspectFit];
[_scrollView sizeToFit];
[_scrollView setContentSize:CGSizeMake(_imageView.frame.size.width, _imageView.frame.size.height)];
Upvotes: 1
Views: 915
Reputation: 4728
I should've put this up a long time ago rather than just comment on Matt's answer, sorry.
As Matt alludes, UIScrollView works it's magic (zoom & pan) by manipulating the transform property of its content view. If you try to manipulate the transform property on the same UIView then you will be sabotaging the scrollView's efforts. You need to apply your rotation at a different level in the view hierarchy, consider rotating the scrollView itself. Best
Upvotes: 5
Reputation: 534987
The problem is that when a user zooms the transform is reset
Because that is what zooming is. It is the application of a scale transform to the image. That scale transform is replacing your rotation transform.
You can try implementing the zoom
delegate method so as to reapply the rotation transform again and again as the user zooms. But remember to apply it relative to the scale transform or you'll lose the zoom.
Upvotes: 3