[英]How to track user's gestures and taps across the entire app?
iOS 7/8是否支持在用户手势和轻击整个应用程序之后进行跟踪,而无需在每个视图上进行字面收听?
Yes you can achieve this by attaching a gesture recognizer to your UIWindow in your AppDelegate
. 是的,您可以通过将手势识别器附加到AppDelegate
的UIWindow来实现。 UIWindow
is a subclass of UIView
, and because it manages your views anyway you can attach a gesture recognizer here. UIWindow
是UIView
的子类,并且由于它仍然可以管理视图,因此可以在此处附加手势识别器。
Conform to UIGestureRecognizerDelegate
in your AppDelegate
, attach whatever gesture recognizer you want to your UIWindow
instance (of course set the delegate as well), and override the following: UIGestureRecognizerDelegate
AppDelegate
UIGestureRecognizerDelegate
,将所需的任何手势识别器附加到UIWindow
实例(当然也设置委托),并覆盖以下内容:
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
//do whatever with your touch
return false;
}
Returning false is important, so that your code won't interfere with your regular app function; 返回false很重要,因此您的代码不会干扰您的常规应用程序功能; but it is important to note that because you have to return false, in order for this to work you must do all your UITouch work in the location as noted above. 但要注意的是,由于必须返回false,因此要使其正常工作,必须在上述位置完成所有UITouch工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.