我在这上面花了几个小时。我已经初始化了UIPageViewController
with UIPageViewControllerNavigationOrientationHorizontal
,但由于某种原因viewControllerBeforeViewController
当用户垂直平移时调用。
此外,当发生这种情况时,不会进行翻页,并且didFinishAnimating:didFinishAnimating:previousViewControllers:transitionCompleted
根本没有被调用。这意味着页面视图控制器知道这是垂直移动。
这是初始化代码 -
- (void)initPageViewController
{
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options:nil];
self.pageViewController.delegate = self;
self.pageViewController.dataSource = self;
[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.
self.pageViewController.view.frame = self.view.bounds;
[self.pageViewController didMoveToParentViewController:self];
// Leave only pan recognizers enabled, so buttons positioned inside a page would work.
for (UIGestureRecognizer *gr in self.pageViewController.gestureRecognizers)
{
if ([gr class] != [UIPanGestureRecognizer class])
gr.enabled = NO;
}
}
有任何想法吗?
我最初偶然发现你面临同样的问题 - 但我似乎已经针对我的情况修复了它。
基本上,我要做的就是为附加到的所有手势识别器设置一个委托。UIPageViewController
。所以,在创建之后不久UIPageViewController
,我做了:
for (UIGestureRecognizer *gr in self.book.gestureRecognizers)
gr.delegate = self.book;
where book
是我的习惯UIPageViewController
(我基本上将自己设置为代表)。最后,将此方法添加到您的UIPageViewController
限制任何垂直平移(或使用注释掉的行来限制水平平移)。
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]])
{
UIPanGestureRecognizer *panGestureRecognizer = (UIPanGestureRecognizer *)gestureRecognizer;
CGPoint translation = [panGestureRecognizer translationInView:self.view];
return fabs(translation.x) > fabs(translation.y);
// return fabs(translation.y) > fabs(translation.x);
}
else
return YES;
}
我被暗示了这一点,感谢这个答案 https://stackoverflow.com/a/7118827/1089059- 只要确保过滤掉UIPanGestureRecognizer
s only.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)