使用 UIGestureRecognizer 隐藏视图中的导航栏和工具栏,其中包含 UIWebView 和 UIImage

发布于 2024-11-07 04:49:21 字数 351 浏览 1 评论 0原文

我正在使用 UIImageView、2xUIWebView 创建 UIViewController。 在此处输入图像描述

我试图用 UITapGestureRecognizer 隐藏 UINavigationBar 和 UIToolBar,没问题,但是当我在 ViewController 中添加时UIWebView 它停止工作。在“UIWebView youtube 播放器”中 - 我有从 youtube 播放视频的代码。当我触摸“白色区域”或 UIImageView 时,手势识别器可以工作,但是当我触摸 UIWebView 时,什么也没有发生。请帮助我修复它。谢谢

I'm creating a UIViewController with UIImageView, 2xUIWebView.
enter image description here

I'm trying to hide UINavigationBar and UIToolBar with UITapGestureRecognizer, It's no problem, but when i added in ViewController UIWebView it stop works. In "UIWebView youtube player" - I Have code which plays video from youtube. When I'm touching in "white area" or UIImageView- gesture recognizer works, but when I'm touching UIWebView - nothing happens. Help me please fix it. Thank you

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

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

发布评论

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

评论(2

世界等同你 2024-11-14 04:49:21

如果您将手势识别器添加到父视图中,那么您就做错了。您应该将其附加到 webView。

[self.webView addGestureRecognizer:singleFingerTap];

而不是

[self.view addGestureRecognizer:singleFingerTap];

If you are add gesture recognizer to the parent view than you are doing it wrong. You should attach it to the webView instead.

[self.webView addGestureRecognizer:singleFingerTap];

instead of

[self.view addGestureRecognizer:singleFingerTap];
我不咬妳我踢妳 2024-11-14 04:49:21

UIWebView由一些子视图组成,而子视图已经添加了一些手势识别器,所以如果你只是给UIWebView添加手势识别器,它不会被处理,因为视图树中更深的UIView会先处理手势。为了允许新添加的手势识别器和内置手势识别器同时处理,您应该采用 UIGestureRecognizerDelegate 协议来允许这样做。

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

yourTapRecognizer.delegate = self; //add this line with you UIGestureRecognizer alloc/init

有关一些详细信息,请参阅此博客:如何向 UIWebview 点击手势添加自定义流程

UIWebView consists of some subviews, and the subviews have already add some gesture recognizers, so if you just add gesture recognizer to UIWebView, it will not be processed, because the deeper UIView in the view tree will handle the gesture first. To allow both the new added gesture recognizer and the built-in gesture recognizer processed simultaneously, you should adopt the UIGestureRecognizerDelegate protocol to allow this.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

yourTapRecognizer.delegate = self; //add this line with you UIGestureRecognizer alloc/init

for some detail information see this blog: How to Add Custom Process to UIWebview Tap Gestures

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