似乎按钮根本没有被按下。
我试过了:
但是,这里有问题
如果 UIPageViewController 的页面转换是 UIPageViewControllerTransitionStyleScroll 则
self.view.gestureRecognizers = self.pageViewController.gestureRecognizers;
NSLog(@"%@",self.pageViewController.gestureRecognizers.description);
NSLog(@"%@",self.pageViewController.gestureRecognizers.description);
将只是空的。
我尝试将自己的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);
}