Restrict UIPageViewController (with TransitionStyleScroll) pan gesture to a certain area

后端 未结 2 1624
感动是毒
感动是毒 2021-01-18 12:19

In my app I have a RootPageViewController which contains the UIPageViewController and one or more DetailPageViewController with a UITableView as a childview.



        
2条回答
  •  渐次进展
    2021-01-18 12:50

    I do it by subclassing the UIPageViewController, finding its UIScrollView (iterate self.subviews), and adding a new UIPanGestureRecognizer to that scrollView.

    I set my subclassed UIPageViewController to be the delegate of that new UIPanGestureRegognizer. I then implement two delegate methods:

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
    {
      return NO;
    }
    

    and in

    - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
    

    I decide if I want to "eat the event" (reply YES) or if I want the original UIPanGestureViewRecognizer of the UIScrollView to handle it (reply NO). So, the YES-reply means the UIPageViewController will not scroll to the next ViewController.

提交回复
热议问题