6

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

                          DetailPageViewController
                        / 
RootPageViewController  - DetailPageViewController
                        \
                          DetailPageViewController

On top of every DetailPageViewController is a little space where it should be possible to swipe and get to the next DetailPageViewController.

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

In the iOS 7 weather app is a scrollview with the whole weak forecast who somehow overwrites or disables the the pan of the UIPageViewController.

How can I recreate such behavior ?

Sorry for the missing screenshots

ioboi
  • 1,128
  • 6
  • 10

2 Answers2

4

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.

scrrr
  • 5,135
  • 7
  • 42
  • 52
  • 2
    http://www.lukaszielinski.de/blog/posts/2014/03/26/restrict-panning-of-uipageviewcontroller-to-certain-area/ Much detailed answer here which says the same thing – Tushar Koul Mar 31 '14 at 09:15
  • Well, no need to add an additional panGestureRecognizer! You can have the same behavior with the supplied one and without having to do all this gestureRecognizershouldRecognizeSimultaneouslyWithGestureRecognizer: business... ;-) – mramosch Oct 19 '16 at 23:29
1

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) } 
}
ingo
  • 11
  • 2