UIScrollView 中的 UIWebView 和触摸通知

发布于 2024-10-30 02:49:26 字数 492 浏览 2 评论 0原文

我的视图控制器具有以下视图层次结构:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月无声 2024-11-06 02:49:26

我认为您需要找到另一种构建用户界面的方法。苹果明确 建议不要在滚动视图中嵌入滚动视图

您不应嵌入 UIWebView 或
UIScrollView 中的 UITableView 对象
对象。如果你这样做,意想不到的
行为可能是因为触摸而导致的
两个对象的事件可以是
混淆并错误处理。

如果不知道您想要实现什么目标,就很难提出有效的替代方案。标签?屏幕底部的滑动手势?网页视图中的链接?

I think you'll need to find an alternative way of building your UI. Apple explicitly recommend against embedding scroll views inside scroll views:

You should not embed UIWebView or
UITableView objects in UIScrollView
objects. If you do so, unexpected
behavior can result because touch
events for the two objects can be
mixed up and wrongly handled.

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?

倾城°AllureLove 2024-11-06 02:49:26

您可以这样做,但需要小心触摸事件,以便滚动视图不会处理用于 Web 视图的触摸。

下面代码中的导入行是 [[[wv1 subviews] lastObject] setScrollEnabled:NO];

for (NSString *link in links) {
    UIWebView *wv1 = [[UIWebView alloc] initWithFrame:frame];
    NSURL *aurl = [site getUrl:link local:YES];
    [wv1 loadRequest:[NSURLRequest requestWithURL:aurl]];
    [[[wv1 subviews] lastObject] setScrollEnabled:NO];
    [scrollView addSubview:wv1];
    [wv1 release];  
}

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];

for (NSString *link in links) {
    UIWebView *wv1 = [[UIWebView alloc] initWithFrame:frame];
    NSURL *aurl = [site getUrl:link local:YES];
    [wv1 loadRequest:[NSURLRequest requestWithURL:aurl]];
    [[[wv1 subviews] lastObject] setScrollEnabled:NO];
    [scrollView addSubview:wv1];
    [wv1 release];  
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文