为什么在UWestureRecognizer添加到UIWindow后iPad变得无响应?

编程入门 行业动态 更新时间:2024-10-24 17:30:23
本文介绍了为什么在UWestureRecognizer添加到UIWindow后iPad变得无响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

背景:我需要查看应用程序中发生的每个UITouch,看看UITouch是否不在某个UIImageView中。

Background: I need to look at every UITouch that happens in an application and see if the UITouch is NOT inside a certain UIImageView.

WildcardGestureRecognizer看起来非常有前景我试了一下。 (代码在这里): 如何拦截触摸MKMapView或UIWebView对象上的事件?

WildcardGestureRecognizer looked very promising and I tried it. (Code is here): How to intercept touches events on a MKMapView or UIWebView objects?

它适用于沙箱/快速创建的应用程序。但是,该应用程序并未反映实际目标项目的复杂性。目标项目有一个Table View Controller等等。

It worked great for a sandbox/quickly-created application. However that application didn't reflect the complexity that the actual target project has. The target project has a Table View Controller and more.

将WildcardGestureRecognizer添加到更复杂的iPad应用程序后,我看到手势识别器后没有其他控件可用添加并单击一下。

After adding the WildcardGestureRecognizer to the more involved iPad application, I see that none of the other controls work after the gesture recognizer is added and one click happens.

这是我正在玩这个想法的一些代码。同样,沙箱代码还没有控件(例如表视图控制器甚至是UIButton),以便在将手势识别器添加到UIWindow后查看它们是否有效。

Here's some code where I was playing with the idea. Again, the sandbox code does not yet have controls on it (such as a Table View Controller or even a UIButton) to see if they work after adding the gesture recognizer to the UIWindow.

我应该选择UIWindow以外的其他内容来添加手势识别器,或者我是否会遇到同样的问题?有更好的方法吗?

Should I pick something other than the UIWindow to add the gesture recognizer to or am I going to run into the same problem regardless? Is there a better way?

沙箱代码: https: //github/finneycanhelp/GestureKata

推荐答案

您可能想尝试其他方法:创建 UIWindow 子类,在您的XIB中使用它并覆盖 hitTest:withEvent: 。它返回已被选中以接收触摸事件的视图。

You might want to try another approach: create a UIWindow subclass, use that in your XIB and override hitTest:withEvent:. It returns the view that has been "selected" to receive the touch events.

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { UIView *v; v = [super hitTest:point withEvent:event]; if (v == myImageView) { // Do something. Maybe return nil to prevent the touch from getting // sent to the image view. } return v; }

在调试时,覆盖此方法也很有帮助。

Overriding this method can also be helpful when debugging.

更多推荐

为什么在UWestureRecognizer添加到UIWindow后iPad变得无响应?

本文发布于:2023-07-19 08:55:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1154920.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:UWestureRecognizer   UIWindow   iPad

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!