Horizontal UIScrollView having vertical UIScrollViews inside - how to prevent scrolling of inner scroll views when scrolling outer horizontal view?

后端 未结 6 900
失恋的感觉
失恋的感觉 2021-02-09 18:50

couldn\'t find a solution for that.

I am building an app, with big scroll view, who has paging (Horizontal). Inside this scroll view, there is a grid of UIView\'s, and a

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-09 19:17

    @stanislaw, I've just tried the solution you suggest on an iPhone device.

    I see your problem.

    Your code does prevent occasional scrolls of vertical views but I believe it is not the simultaneous gesture recognition does the job - comment the entire code you provide for inner views and use the code for the outer scroll view with the following modification:

    @interface OuterHorizontalScrollView : UIScrollView ...
    @property (weak) InnerVerticalScrollView *currentActiveView; // Current inner vertical scroll view displayed.
    @end
    
    @implementation OuterHorizontalScrollView
    - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
        if (self.currentActiveView.dragging == NO) {
            self.currentActiveView.scrollEnabled = NO; // The presence of this line does the job
        }
        return YES;
    }
    
    - (void)scrollViewDidEndDragging:(PlacesScrollView *)scrollView willDecelerate:(BOOL)decelerate {
        self.currentActiveView.scrollEnabled = YES; // This is very likely should be done for all subviews, not only a current.
    }    
    @end
    

提交回复
热议问题