Could somebody advice which formula used to content offset calculation after zoom in UIScrollView? Let's consider following example:
I have a UIScrollView with content view in size (1000, 1000), then if I programmatically setZoomScale
to 2.0 and in scrollViewDidEndZooming:withView:atScale
method I will have the following:
contentSize before zoom = {1000, 1000}
contentOffset before zoom = {0, 0}
scale = 2.000000
contentSize after zoom = {2000, 2000}
contentOffset after zoom = {160, 230}
I need to know how the new value of contentOffset {160, 230} calculated. Is there any dependency of formula that used to calculate the content offset in this case?
Thanks
The default value is 0 for top, bottom, right, and left. contentSize is the size of the content within the UIScrollView and how long it can be within scrollView. Sometimes this is dynamic like pagination or static like a contact list. This might be changing at runtime as well. This can be set programmatically as well.
As the user makes a pinch-in or pinch-out gesture, the scroll view adjusts the offset and the scale of the content. When the gesture ends, the object managing the content view should update subviews of the content as necessary.
UIScrollView is the superclass of several UIKit classes, including UITableView and UITextView. A scroll view is a view with an origin that’s adjustable over the content view. It clips the content to its frame, which generally (but not necessarily) coincides with that of the application’s main window.
A view that allows the scrolling and zooming of its contained views. UIScrollView is the superclass of several UIKit classes, including UITableView and UITextView. A scroll view is a view with an origin that’s adjustable over the content view.
This may or may not be relevant, but note that 160x230 is half the resolution of the iPhone, less the status bar: 320x460. Try changing the UIScrollView's frame, or its superview's frame, and see how this affects the numbers.
EDIT: Come to think of it, it makes perfect sense that the offset is half the size of the scroll view, as it will expand equally in both directions. So, the formula would be: contentOffset = (scrollView.frame.size.width/2 * (scaleAfter - scaleBefore), scrollView.frame.size.height/2 * (scaleAfter - scaleBefore))
.
Therefore, if the scale was 4.0f, the offset would be: (320/2 * (4-1), 460/2 * (4-1)) => (480, 690)
. Try a scale of 4 and see if (480, 690) comes out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With