1
votes

I have a parent UIScrollView containing a bunch of child UIScrollViews, every scrollview can scroll in every direction. On the top of each child, there is an UIView, subview of the parent.

I want to enable the parent scrolling only if the user is dragging from one of the upper UIView.

Any idea to do so ? Thanks !

2

2 Answers

0
votes

You can try to detect where the user is touching using touchesBegan: and if it is within one of the UIViews then you can disable scrolling (or even interaction) for all the child scrollViews. So in code:

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

        //check if touch is in one of the UIViews

        //if so disable child UIScrollView interaction like so:
        childScrollView.scrollEnabled = NO;
    }

Then in the touches ended method just reenable scrolling on the child scrollViews.

0
votes

Okay, I have finally found something ! By overriding the callback -(UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event of the parent scrollview.

`-(UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event {

if (CGRectContainsPoint(myFrame, point))
{
    self.scrollEnabled = YES;
}
else
{
    self.scrollEnabled = NO;
}

return [super hitTest:point withEvent:event];

}`