UIScrollView 中的 UIWebView 和触摸通知
我的视图控制器具有以下视图层次结构:
UIView
'- UIScrollView
'- UIWebView
'- UIWebView
'- ... more UIWebViews
UIScrollView 已启用分页,并且每个页面包含一个 UIWebView。 UIScrollView 占据整个屏幕,UIWebView 也是如此。
现在我的问题是我需要检测整个屏幕上的触摸。我猜想 UIScrollView 以某种方式吃掉了其中的大部分(并且由于 UIWebView 也包含滚动视图,所以事情变得更加复杂)。
我尝试对每个视图进行子类化,并尝试了 TouchBegan 和点击手势识别器,但什么也没做。我所能得到的只是 UIWebView 上非常不可靠的手势识别器,它在 20 次点击中工作一次,非常随机且非常奇怪。
我应该如何解决这个问题?我需要touchesBegan和touchesEnded或点击手势。
I have view controller with following view hierarchy:
UIView
'- UIScrollView
'- UIWebView
'- UIWebView
'- ... more UIWebViews
UIScrollView has paging enabled and each page contains one UIWebView. UIScrollView occupies entire screen, UIWebView as well.
Now my problem is that I need to detect touches on entire screen. I guess that UIScrollView somehow eats most of those (and since UIWebView contains scroll view as well, things got even more complicated).
I tried subclassing each of those views and tried both touchesBegan and tap gesture recognizer but nothing. All I was able to get was very unreliable gesture recognizer on UIWebView, it worked once in 20 taps, very random and very weird.
How should I solve this? I need touchesBegan and touchesEnded or tap gesture.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您需要找到另一种构建用户界面的方法。苹果明确 建议不要在滚动视图中嵌入滚动视图:
如果不知道您想要实现什么目标,就很难提出有效的替代方案。标签?屏幕底部的滑动手势?网页视图中的链接?
I think you'll need to find an alternative way of building your UI. Apple explicitly recommend against embedding scroll views inside scroll views:
Without knowing what you're trying to achieve it's difficult to be able to suggest a valid alternative. Tabs? A swipe gesture at the bottom of the screen? Links inside the webviews?
您可以这样做,但需要小心触摸事件,以便滚动视图不会处理用于 Web 视图的触摸。
下面代码中的导入行是 [[[wv1 subviews] lastObject] setScrollEnabled:NO];
You can do that, but you need to be careful with the touch events so that scrollview does not handle touches intended for webview.
Import line on the code below is [[[wv1 subviews] lastObject] setScrollEnabled:NO];