UIPageController中的UIViewController如何获取触摸事件?

Sep*_*gus 8 objective-c xcode4.5

似乎按钮根本没有被按下.

我试过了:

UIPageViewController手势识别器

然而,这是捕获

如果UIPageViewController的页面转换是UIPageViewControllerTransitionStyleScroll那么

self.view.gestureRecognizers = self.pageViewController.gestureRecognizers;
NSLog(@"%@",self.pageViewController.gestureRecognizers.description);
NSLog(@"%@",self.pageViewController.gestureRecognizers.description);
Run Code Online (Sandbox Code Playgroud)

只会是空的.

我尝试将自己的gestureRecoqnizers而不是按钮添加到UIViewControllers的子视图中.它仍然无法正常工作.

所以我有一个UIPageViewController,它显示一个UIViewController,它的视图有一些按钮.如何按下该按钮?

我也在这里试过两个解决方案:

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

没有用.首先,我无法禁用UIPageViewController的手势重新整理器,因为没有这样的东西.在scrollView模式下,UIPageViewController没有手势重新整理器.

我试图将自己的手势重新整理器添加到我自己的按钮,但这些从未被调用过.

我希望UIPageViewController仍然可以处理滑动.但不要点击.

我无法访问UIPageViewControllers的手势重新生成器,因为self.pageViewController.gestureRecognizers为空.UIPageViewController似乎只是"吸收"所有点击事件.所以我的按钮没有得到它.

我可以在UIPageViewController前添加按钮,但该按钮将吸收我希望UIPageVIewController仍然处理的滑动动作.

顺便说一句,如果我们使用来自IOS的模板(创建基于页面的应用程序,并更改过渡以滚动pageviewcontroller.gesturerecoqnizers将为空

- (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);
}
Run Code Online (Sandbox Code Playgroud)

Jis*_*say 0

也许您可以在 UIPageViewController 中设置自定义手势识别器。这样,您将能够通过在手势识别器委托(UIPageViewController 的委托)中实现这一点来过滤 UITouch 事件:

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

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

这样,您将告诉 UIPageViewControllergestureRecognizer 不要关心一根手指的触摸。你必须尝试一下,但我认为它可能会起作用。这里的问题是你必须要求用户用两根手指滑动......

在这里查看其他答案