8

It seems that the button simply doesn't get pressed.

I tried:

UIPageViewController Gesture recognizers

However, here is the catch

if page transition of UIPageViewController is UIPageViewControllerTransitionStyleScroll then

self.view.gestureRecognizers = self.pageViewController.gestureRecognizers;
NSLog(@"%@",self.pageViewController.gestureRecognizers.description);
NSLog(@"%@",self.pageViewController.gestureRecognizers.description);

will simply be empty.

I tried adding my own gestureRecoqnizers instead of button into the UIViewControllers's subview. It still doesn't work.

So I have a UIPageViewController that display a UIViewController whose view has some button. How do I get that button pressed?

I also tried both solutions here:

http://emlyn.net/posts/stopping-gesture-recognizers-in-their-tracks

None works. First of all I cannot disable gesture recoqnizers of the UIPageViewController because there is no such thing. In scrollView mode, UIPageViewController doesn't have gesture recoqnizers.

I tried to add my own gesture recoqnizers to my own button but those are never called.

I want the UIPageViewController to still handle swipe though. But not tap.

I can't access the gesture recoqnizers of UIPageViewControllers because self.pageViewController.gestureRecognizers is empty. The UIPageViewController seems to just "absorb" all tap events. So my button doesn't get it.

I can add button in front of UIPageViewController but that button will absorb the swiping action which I want UIPageVIewController to still handle.

By the way if we uses the template from IOS (Create a page based app, and change the transition to scroll the pageviewcontroller.gesturerecoqnizers will be empty

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    // Configure the page view controller and add it as a child view controller.
    self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];//Turn this to scroll view
    self.pageViewController.delegate = self;

    SDDataViewController *startingViewController = [self.modelController viewControllerAtIndex:0 storyboard:self.storyboard];
    NSArray *viewControllers = @[startingViewController];
    [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:NULL];

    self.pageViewController.dataSource = self.modelController;

    [self addChildViewController:self.pageViewController];
    [self.view addSubview:self.pageViewController.view];

    // Set the page view controller's bounds using an inset rect so that self's view is visible around the edges of the pages.
    CGRect pageViewRect = self.view.bounds;
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        pageViewRect = CGRectInset(pageViewRect, 40.0, 40.0);
    }
    self.pageViewController.view.frame = pageViewRect;

    [self.pageViewController didMoveToParentViewController:self];

    // Add the page view controller's gesture recognizers to the book view controller's view so that the gestures are started more easily.
    self.view.gestureRecognizers = self.pageViewController.gestureRecognizers;
    NSLog(@"%@",self.pageViewController.gestureRecognizers.description); //This is empty
    while (false);
}
Community
  • 1
  • 1
Septiadi Agus
  • 1,775
  • 3
  • 17
  • 26
  • Does the button have a target and action? – Wain Aug 01 '13 at 06:07
  • of course. I got that straight. It works fine if not inside UIPageViewController. – Septiadi Agus Aug 01 '13 at 06:43
  • So why the gesture recognizer? And did you set your controller as the delegate and check the delegate methods were called? – Wain Aug 01 '13 at 06:50
  • 1
    The delegate of what? Of the gesture recoqnizer of the UIPageViewController? I can't access the gesture recoqnizer. The UIPageViewController seems to just "absorb" all tap events. So my button doesn't get it. I can add button in front of UIPageViewController but that button will absorb the swiping action which I want UIPageVIewController to still handle. – Septiadi Agus Aug 01 '13 at 07:12
  • did you find a solution? – Crashalot Oct 14 '16 at 23:13

1 Answers1

0

Maybe you can set up a custom gesture recognizer in your UIPageViewController. This way, you will be able to filter through UITouch Events, by implementing this in your gesture recognizer delegate (the one for your UIPageViewController) :

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gesture shouldReceiveTouch:(UITouch *)touch {            

if (touch.tapCount > 1) { // It will ignore touch with less than two finger 
       return YES;
   }
   return NO;
}

This, you will tell the UIPageViewController gestureRecognizer to not care about touch with one finger. You'll have to try it, but i think it might do the trick. The problem here is you have to ask your user for a two-finger swipe...

Check here for an other answer

Community
  • 1
  • 1
Jissay
  • 550
  • 9
  • 28