• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

UIPageViewController 捕获所有 UITapGestureRecognizer 事件

用户头像
it1352
帮助1

问题说明

在键盘上度过了漫长的一天,所以我伸出手:-)

It's been a long day at the keyboard so I'm reaching out :-)

我在一个典型的实现中有一个 UIPageViewController,它基本上遵循 Apple 的标准模板.我正在尝试添加一个叠加层,允许用户执行诸如触摸按钮以跳转到某些页面或关闭视图控制器以转到应用程序的另一部分之类的操作.

I have a UIPageViewController in a typical implementation that basically follows Apple's standard template. I am trying to add an overlay that will allow the user to do things like touch a button to jump to certain pages or dismiss the view controller to go to another part of the app.

我的问题是 UIPageViewController 正在从我的叠加子视图中捕获所有事件,我正在努力寻找可行的解决方案.

My problem is that the UIPageViewController is trapping all events from my overlay subview and I am struggling to find a workable solution.

这是一些帮助示例的代码...

Here's some code to help the example...

在 viewDidLoad

// Page creation, pageViewController creation etc....

self.pageViewController.delegate = self;

[self.pageViewController setViewControllers:pagesArray
                                  direction:UIPageViewControllerNavigationDirectionForward
                                   animated:NO
                                completion:NULL];

self.pageViewController.dataSource = self;

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

// self.overlay being the overlay view

if (!self.overlay) 
{
   self.overlay = [[MyOverlayClass alloc] init];  // Gets frame etc from class init
   [self.view addSubview:self.overlay];
}

这一切都很好.叠加层被创建,正如你所期望的那样,它会显示在 UIPageViewController 的页面顶部.当页面翻转时,它们会在覆盖层下方翻转 - 再次如您所料.

This all works great. The overlay gets created, it gets show over the top of the pages of the UIPageViewController as you would expect. When pages flip, they flip underneath the overlay - again just as you would expect.

然而,self.overlay 视图中的 UIButtons 永远不会获得点击事件.UIPageViewController 响应所有事件.

However, the UIButtons within the self.overlay view never get the tap events. The UIPageViewController responds to all events.

我尝试根据此处的建议覆盖 -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch ,但没有成功.

I have tried overriding -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch per the suggestions here without success.

UIPageViewController 手势识别器

我已经尝试手动捕获所有事件并自己处理它们 - 不起作用(老实说,即使这样做了,它看起来也有点像黑客).

I have tried manually trapping all events and handling them myself - doesn't work (and to be honest even if it did it would seem like a bit of a hack).

有没有人有关于如何捕获事件的建议,或者可能有更好的方法在 UIPageViewController 的顶部使用叠加层.

Does anyone have a suggestion on how to trap the events or maybe a better approach to using an overlay over the top of the UIPageViewController.

非常感谢所有帮助!!

正确答案

#1

尝试遍历 UIPageViewController.GestureRecognizers 并指定 self 作为这些手势的代理并实现

Try to iterate through UIPageViewController.GestureRecognizers and assign self as a delegate for those gesture and implement

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;

你的代码可能是这样的:

Your code may be like this:

在视图中DidLoad

In viewDidLoad

for (UIGestureRecognizer * gesRecog in self.pageViewController.gestureRecognizers)
{
        gesRecog.delegate = self;
}

并添加以下方法:

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if (touch.view != self.pageViewController.view]
    {
        return NO;
    }
    return YES;
}

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfickk
系列文章
更多 icon
同类精品
更多 icon
继续加载