gpt4 book ai didi

当方向设置为水平时,UIPageViewController 响应垂直平移

转载 作者:行者123 更新时间:2023-12-03 01:27:59 25 4
gpt4 key购买 nike

我已经在这上面花了几个小时了。我已使用 UIPageViewControllerNavigationOrientationHorizo​​ntal 初始化了 UIPageViewController,但由于某种原因,当用户垂直平移时会调用 viewControllerBeforeViewController

此外,当发生这种情况时,不会发生页面翻转,并且根本不会调用 didFinishAnimating:didFinishAnimating:previousViewControllers:transitionCompleted 。这意味着页面 View Controller 知道这是垂直移动。

这是初始化代码-

- (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 的所有手势识别器设置一个委托(delegate)。因此,在创建 UIPageViewController 后不久,我做了:

for (UIGestureRecognizer *gr in self.book.gestureRecognizers)
gr.delegate = self.book;

其中 book 是我的自定义 UIPageViewController (我基本上将自己设置为委托(delegate))。最后,将此方法添加到您的 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;
}

感谢this answer向我暗示了这一点- 只需确保仅过滤掉 UIPanGestureRecognizer

关于当方向设置为水平时,UIPageViewController 响应垂直平移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11256812/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com