2

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.

petershine
  • 3,190
  • 1
  • 25
  • 49

2 Answers2

2

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.

petershine
  • 3,190
  • 1
  • 25
  • 49
0

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.

Community
  • 1
  • 1
Chris Conover
  • 8,889
  • 5
  • 52
  • 68