I’m working with a UIScrollView to display a large document, I want to restrict the area that the user can view somehow. I have almost achieved the desired result with the following code:
[childView setFrame:CGRectMake(offsetX, offsetY, contentWidth, contentHeight)];
[scrollView setContentSize:CGSizeMake(contentWidth, contentHeight)];
With offsetX and offsetY being negative numbers to move the child view outside of the scrollview area. This works perfectly at zoom level 1.0 but not at any other zoom levels. I have implemented - (void)setZoomScale:(float)zoomScale like this:
- (void)setZoomScale:(float)zoomScale {
[super setZoomScale:zoomScale];
[childView setFrame:CGRectMake(offsetX * zoomScale, offsetY * zoomScale, contentWidth, contentHeight)];
}
But this doesn’t work, the offset gradually gets further out the more the view is zoomed. What is the best way to achieve this?
Thanks,
J
Obviously you could fix the minimum and maximum zoom scale to 1.
However, it works for me if I set the contentSize in scrollViewDidZoom:
btw, make sure you turn bounces off to check accurately: