How to reset (i.e. Un-zoom) a UIScrollView?

I have a UIScrollView that contains an image and a segmented control that allows the user to switch the image inside ScrollView. If I just change the image inside the UIImageView, it will display the new image in an enlarged state. How to return UIScrollView back to a state without magnification?

+1
source share
2 answers

I have a detailed discussion of how (and why) scaling UIScrollView works on github.com/andreyvit/ScrollingMadness/ .

(The link also contains a description of how to programmatically scale UIScrollView, how to emulate paging in the style of a photo library + zoom + scroll, an example project and the ZoomScrollView class that encapsulates some zoom magic.)

Quote:

UIScrollView does not have the concept of “current zoom level” because each of its subviews can have its own current zoom level. Note that there is no field in UIScrollView to maintain the current zoom level. However, we know that someone preserves this zoom level because if you increase the zoom of the preview, then reset it to CGAffineTransformIdentity and then hold it again, you will notice that the previous subview zoom level has been restored.

Indeed, if you look at the disassembly, the UIView retains its own zoom level (inside the UIGestureInfo object that the _gestureInfo field points to). It also has a set of good undocumented methods like zoomScale and setZoomScale:animated: (Keep in mind, he also has a bunch of rotation-related methods, maybe we'll get gesture support soon).

However, if we create a new UIView just for scaling and add our real scalable representation as our child, we will always start from scale level 1.0. My implementation of software scaling is based on this trick.

+2
source

If you do not redraw your view at the end of the pinch scaling event, then the scaling factor is set using the transform property of the view, which you return from the viewForZoomingInScrollView: delegate method. To reset this increase, set the transform property of the form CGAffineTransformIdentity.

Beware, however, that your next scaling-scaling operation will start from the moment the previous scaling effect has ceased (i.e. your new scale will be ignored). To get around this, you may need to implement some of what I will describe here .

0
source

All Articles