I want to pan to a certain point in my UIScrollView and while doing so also zoom into the maximum zoom level. Leaving out the zoom rect calculation here, it seems that zoomToRect needs to be called twice to zoom and pan where I want it to.
[self performSelector:@selector(zoom) withObject:nil afterDelay:1.0];
[self performSelector:@selector(zoom) withObject:nil afterDelay:2.0];
[self performSelector:@selector(zoom) withObject:nil afterDelay:3.0];
- (void) zoom
{
[self.imageScrollView zoomToRect:(CGRect){ 913.556, 0, 320, 465 }
animated:YES];
}
The first zoom call zooms in, but it takes the second call to actually pan to the correct position. Once at the proper position the 3rd call does nothing – which is what I already expected for the 2nd call.
What’s the problem here? According to the Apple docs I would expect it to just work on the first call.
A sample project is available on github.
The “problem” is the overridden layoutSubviews which centers the image view. This effects the position of the resulting frame after the first call of
I did some tests and found a quick hack, maybe this guides you to a solution which fits your needs:
1.) Override zoomToRect: to indicate that you doing a automatic zooming:
2.) Make the adjustment of the image view in layoutSubviews depend on the automaticZooming state:
3.) Reset automaticZooming state after a zooming is done: