How to get the contentSize, zoomScale and contentOffset of scrollView properly in my case?

380 views Asked by At

I having the following scenario:

  • A scrollView which contains an imageView.
  • This imageView is zoomable from 1.0 to 5.0 scale value.
  • Whenever the orientation changes, I resize the imageView to a specific aspect ratio and then set the contentSize of scrollView to the size of the contained imageView.

  • When the scrollView is not zoomed, the imageView resizes appropriately as per my resize code during any orientation.

  • When my scrollView is zoomed in the initial orientation (the orientation during which it was generated), panning the scrollView to the edges goes well.
  • (Issue:) In the zoomed state, if the orientation of device changes, the imageView frames are recalculated by my resize code and zoomScale is set to 1. However, if I zoom again in the new orientation, I find that the imageView gets a some 100 to 200 pixels of offset. This causes the imageView to hide some contents on one edge ( i cannot pan more to view the edge ) and it scrolls extra leaving a gap on the other edge which contains nothing.

How can I get this corrected ? I want the scrollView's contentSize to be such that be its internal imageView in zoomed state or not, after any orientation, the zoomed imageView should be able to pan in all directions till its edge meet the edge of its parent scrollView.

1

There are 1 answers

2
DimasSup On

You should not resize image view. Use [imageView sizeToFit] . You should recalculate zoom of scroll view for fit ImageView.