Tyler Tyler - 10 months ago 26
Swift Question

disabling swiping on uipageviewcontroller for certain area of screen

I have a uipageviewcontroller and the pages have an area on the screen where there is a uitableview. I want the user to only be able to swipe through pages outside of that uitableview.

I can't seem to find where these gesture recognizers are hiding. I am setting them up as delegates like this:

self.view.gestureRecognizers = self.pageViewController?.gestureRecognizers
for gesture in self.view.gestureRecognizers!{
// get the good one, i discover there are 2
if(gesture is UIPanGestureRecognizer)
// replace delegate by yours (Do not forget to implement the gesture protocol)
(gesture as! UIPanGestureRecognizer).delegate = self

I am seeing ispan in the logs so it seems to find some uipangesturerecognizer but when I override the function like this:

func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
println("gesture should begin")
var point = gestureRecognizer.locationInView(self.view)
return true

it doesn't print out "gesture should begin" at all... I have the class set as a
what am I doing wrong? I'm guessing I have the wrong gesture recognizers set as delegates how can I set the correct ones as delegates?


Could something like this work?

func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {

    if(touch.view == <your tableView>){
        return false
        return true

You might need to also test which gestureRecognizer it is (the one from the pageView or the one from the tableView).