问题
The minimum scale is 0.5
The maximum scale is 2.0
I need to always use larger contentSize
for UIScrollView
to be able to drag around the content. So, as the CGRect
of the content is changing, contentSize
of UIScrollView
is also changing.
However, as I zoom out, if the scale is going below 1.0, contentOffset
is abruptly changed to {0.0, 0.0}, making it very difficult to resize the content while keep it's position to the overlay view (e.g. a clothe image).
In other words, I can't make the content view smaller while keeping it positioned at the center of the UIScrollView
.
Please help me to find the right way to use zoom in/out with UIScrollView
while keeping the position of the content view.
回答1:
The solutions is basically about using contentInset
at initial setup to keep the content at the center, instead of contentOffset
. With contentInset
being unmodified, zoomed in or out object can be at the center all the time.
回答2:
This has been answered pretty well in the post: UIScrollView with centered UIImageView, like Photos app
In particular, refer to JosephH's answer which itself is culled from the 2010 WWDC presentation.
This is also covered in Matt Neuburg's book, using the same WWDC reference: http://www.amazon.com/Programming-iOS-6-Matt-Neuburg/dp/1449365760/ref=sr_1_1?ie=UTF8&qid=1367363707&sr=8-1&keywords=programming+ios6
The source of which is available here (see chapter 20): https://github.com/mattneub/Programming-iOS-Book-Examples
The open question for me, is can this not be done as part of the constraints.
来源:https://stackoverflow.com/questions/9197572/using-uiscrollview-when-zooming-out-how-can-i-keep-the-content-view-at-the-cen