0
votes

I add a sub-ScrollView to a main-ScrollView, both of them are able to horizontal scrolling. when I scroll the sub-scrollview to the (right or left) edge, if I continue to scroll right or left, it will cause main-scrollview scroll.

I try to use scrollview didScroll delegate method on each scrollview to resolve it but failed, when main-ScrollView move, the delegate method in sub-scrollview won't be detected. Any idea? Thanks.

2

2 Answers

1
votes

Thanks Alex's answer, but if you set superScrollView.pagingEnabled = true, the exclusiveTouch will not work. Here is my solution:

@interface SuperScrollView : UIScrollView

@end

@implementation SuperScrollView

//disable scroll when sub scrollView drags
-(UIView *)hitTest:(CGPoint) point withEvent:(UIEvent *)event {
    UIView *hint = [super hitTest:point withEvent:event];
    if(!hint){
        return nil;
    }
    if([self isInSubScrollView:hint]){
        self.scrollEnabled = false;
    }
    else{
        self.scrollEnabled = true;
    }
    return hint;
}

-(BOOL)isInSubScrollView:(UIView*)view{
    if([view isKindOfClass:UIScrollView.class]){
        return view != self;
    }
    while (view.superview) {
        view = view.superview;
        if([view isKindOfClass:UIScrollView.class]){
            return view != self;
        }
    }
    return false;
}

@end
0
votes

Try innerScrollView.exclusiveTouch = true