UIScrollView zoom removes transform from UIImageView

醉酒当歌 提交于 2019-12-24 14:01:10

问题


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

回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/33312724/uiscrollview-zoom-removes-transform-from-uiimageview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!