UIPageViewController 捕获所有 UITapGestureRecognizer 事件
问题说明
在键盘上度过了漫长的一天,所以我伸出手:-)
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.
我已经尝试手动捕获所有事件并自己处理它们 - 不起作用(老实说,即使这样做了,它看起来也有点像黑客).
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
.
非常感谢所有帮助!!
正确答案
尝试遍历 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
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20