views:

1493

answers:

1

I have a UIScrollView with nested UIImageViews. Each imageview can zoom, but when I try to scroll the inner scrollview while zoomed on the image, the outer scrollview picks it up and switches imageviews.

How can I prevent this from happening so that the outer scrollview only scrolls when the inner is not zoomed?

+3  A: 

I will post my answer that I got to work to help others out.

One easy way to handle nested UIScrollViews is to share the same delegate. This way, when you detect one UIScrollView scrolling, you can easily share controller logic and apply settings to the other.

to solve this particular problem I was having, All I had to do was keep a BOOL with the current zoom state. Once the app detected that the inner scrollview was zooming,

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView1 {
    return [innerScrollViews objectAtIndex:[self indexOfComicViewWithOffset:currentOffset]]; 
}

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView1 withView:(UIView *)view atScale:(float)scale {
    if (scale == 1) {
     zooming = NO;
     [outerScrollView setScrollEnabled:YES];
    } else {
     zooming = YES;
     [outerScrollView setScrollEnabled:NO];
    }
}
coneybeare