在 UIWebView 中捕获触摸

发布于 2024-12-24 02:55:35 字数 701 浏览 2 评论 0原文

在 UIWebView 中捕获触摸事件时遇到问题。希望能够感知滚动 HTML 页面上单词的触摸,以便在触摸时将超链接插入 HTML [我完全控制]。显然,一些现有代理已经在感应触摸,因为我收到带有放大镜的“复制或定义”弹出窗口。

我已经能够在没有 UIWebView 的应用程序中的不同自定义 UIViewController 中捕获触摸事件,将:放置

self.view.userInteractionEnabled = YES;
self.view.multipleTouchEnabled = YES;

在 viewDidLoad 中并放置

- (BOOL) canBecomeFirstResponder
{
 NSLog(@"canBecomeFirstResponder");
 return YES;
}

在实现中。然后,每当我触摸视图控制器上的任何位置时,都会调用“touchesBegan”。

但相同的代码在自定义视图控制器上无效,其中大部分屏幕都被 UIWebView 覆盖。奇怪的是,底部的小 UIToolBar 中的触摸确实调用了“touches Began”,但 UIWebView 中的某些内容抢占了我的“touchesBegan”。

有没有一种方法可以捕获这些事件而不禁用 UIWebView 想要执行的所有操作?我不想失去滚动和其他功能。

谢谢。新年快乐。

Having trouble capturing touch events in UIWebView. Want to be able to sense touches on words on scrolling HTML page for the purpose of inserting hyperlinks into the HTML [which I fully control] at the point of touch. Obviously some existing agent is already sensing touches, because I get a "Copy or Define" popup with magnifying glass.

I've been able to capture touch events in a different custom UIViewController in my app that has no UIWebView, placing:

self.view.userInteractionEnabled = YES;
self.view.multipleTouchEnabled = YES;

in viewDidLoad and placing

- (BOOL) canBecomeFirstResponder
{
 NSLog(@"canBecomeFirstResponder");
 return YES;
}

in the implementation. Then "touchesBegan" is called whenever I touch anywhere on the view controller.

But the same code isn't effective on the custom view controller where most of the screen is covered by a UIWebView. Curiously, touches in the small UIToolBar at the bottom does indeed call "touches Began" but something in the UIWebView is pre-empting my "touchesBegan".

Is there a way to capture these events without disabling everything UIWebView wants to do? I wouldn't want to lose scrolling and other features.

Thanks. And Happy New Year.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

醉城メ夜风 2024-12-31 02:55:35

捕获 UIWebView 上的触摸是一个痛苦的潘多拉魔盒。由于您只想点击,可能最简单的方法是将 UIView[UIColor clearColor] 作为背景颜色放置在 Web 视图的顶部。在此视图中,覆盖 hitTest: (而不是覆盖 touchesBegan: 等)并使用它来确定点击的位置。 hitTest: 返回一个 UIView,因此如果您希望 Web 视图响应点击,只需从 hitTest: 覆盖返回 Web 视图即可;否则返回覆盖视图,该视图将接收所有 touches... 方法。

Capturing touches on a UIWebView is a Pandora's Box of pain. Since you want only taps, probably the easiest thing to do is to place a UIView with [UIColor clearColor] as the background color over top of the web view. In this view, override hitTest: (instead of overriding touchesBegan: etc.) and use it to determine the location of the tap. hitTest: returns a UIView, so if you want the web view to respond to the tap, just return the web view from your hitTest: override; otherwise return the overlay view, which will then receive all the touches... methods.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文