Limit UIPageViewController pan gestures (with TransitionStyleScroll) to a specific area

In my application, I have a RootPageViewController that contains a UIPageViewController and one or more DetailPageViewController with a UITableView as a child.

DetailPageViewController / RootPageViewController - DetailPageViewController \ DetailPageViewController 

At the top of each DetailPageViewController there is a small space where it should be possible to scroll and move on to the next DetailPageViewController.

  ------------------- | | | | -> UIPageViewController should respond to pan's | | |-------------------| -------------------------------------------- | CellContent | |-------------------| | CellContent | |-------------------| -> UIPageViewController should disable UIPageViewController pan's | CellContent | |-------------------| | ... | 

The iOS 7 weather app has a scrollview with all the weak forecast that somehow overwrites or disables panning of the UIPageViewController.

How can I recreate this behavior?

Sorry for the missing screenshots.

+6
objective-c cocoa-touch uigesturerecognizer uipageviewcontroller
Jan 30 '14 at 16:20
source share
2 answers

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

I found that my subclassified UIPageViewController is a delegate to this new UIPanGestureRegognizer. Then I 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" (answer "YES"), or if I want the original UIPanGestureViewRecognizer from UIScrollView to handle it (NO answer). Thus, the answer YES means that the UIPageViewController will not scroll until the next ViewController.

+4
Mar 26 '14 at 17:03
source share

My solution in Swift:

 let myview = UIView(frame: CGRect(x:0, y:0, width:320, height:320)) //dummy view that defines the area where the gesture works self.view.addSubview(myview) for x in self.pageViewController!.view.subviews { if x is UIScrollView { myview.addGestureRecognizer(x.panGestureRecognizer) } } 
0
Jan 26 '15 at 17:34
source share



All Articles