views:

475

answers:

2

In the iPhone 3.0 SDK, how can I be informed when a zoomToRect:animated: animation completes?

Sometimes the scrollview doesn't zoom at all (if it's already at the proper zoom level), and there doesn't seem to be a way to detect that.

+4  A: 

On your delegate, you can listen for - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale

see UIScrollView and UIScrollViewDelegate

slf
Doesn't work if it doesn't actually zoom.
Adam Ernst
You shouldn't be calling zoomToRect if you don't have to zoom. Use the zooming, zoomBouncing, and zoomScale properties of your scrollview to detect that
slf
https://developer.apple.com/IPhone/library/samplecode/ScrollViewSuite/index.html
slf
+1  A: 

The easiest way would probably to put in a check before starting the animation. If the zoom level is already correct, call [self performSelectorOnMainThread:@selector(myMethod) withObject:id waitUntilDone:NO].

You won't be able to use the same method as scrollViewDidEndZooming, because you can only pass one argument, but it will trigger an asynchronous call on the main thread

Douglas Mayle
A fair workaround; essentially what I ended up doing.
Adam Ernst