views:

317

answers:

1

Using OS 3.1 I'm placing a tap-detecting image view (taken from Apple's Scroll View suite samples) in a UIScrollView and want to zoom twice on the image view when it appears. The first zoom is to make the entire image visible and the second zoom is to zoom in to a specified region. What I have right now is:

- (void)viewDidLoad {
    // After adding scroll view and image view
    imageScrollView.minimumZoomScale = 0.5;
    imageScrollView.maximumZoomScale = 2.75;
    imageScrollView.zoomScale = 1.0;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];    
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDelegate: self];
    [imageScrollView zoomToRect:[imageView frame] animated:YES];
    [UIView commitAnimations];

and the following to detect the end of the first zoom and to trigger the second:

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
    selectedRect.origin.x = 60.0;
    selectedRect.origin.y = 90.0;
    selectedRect.size.width = 90.0;
    selectedRect.size.height = 90.0;

    imageScrollView.minimumZoomScale = 1.0;
    imageScrollView.maximumZoomScale = 2.75;
    imageScrollView.zoomScale = 2.5;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];    
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDelegate: self];
    [imageScrollView zoomToRect:selectedRect animated:YES];
    [UIView commitAnimations];

What happens is that this causes an infinite loop and the scroll view "wiggles" repeatedly between two zoomed-in points. What should I be doing differently? Thank you.

A: 

Surely you just need to check the current zoomScale as the first action in scrollViewDidEndZooming. If you are already zoomed in, don't do your new zoom.

Andiih