为什么在UWestureRecognizer添加到UIWindow后iPad变得无响应? [英] Why Does The iPad Become Nonresponsive After UIGestureRecognizer is Added to UIWindow?

查看:88
本文介绍了为什么在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.com/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变得无响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆