简体   繁体   English

如何在整个应用程序中跟踪用户的手势和点击?

[英]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 . 是的,您可以通过将手势识别器附加到AppDelegateUIWindow来实现。 UIWindow is a subclass of UIView , and because it manages your views anyway you can attach a gesture recognizer here. UIWindowUIView的子类,并且由于它仍然可以管理视图,因此可以在此处附加手势识别器。

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.

相关问题 用户在Iphone中点击UItextview时如何获取整个文本 - How to get the entire text when user taps on UItextview in Iphone iPad应用横向启动时无法识别水龙头和手势 - Taps and gestures not recogized when iPad app launched in landscape 当用户点击我的应用程序中的字段时如何弹出应用程序 - How to pop up an app when user taps a field in my app 如何跟踪 SwiftUI 应用程序中的所有触摸 - How to track all touches across SwiftUI app 如何在 iOS 的整个视图上阻止 2 个手指手势 - How to block 2 finger gestures on an entire view on iOS 用户点击UILocalNotification:它可以将数据传递给应用程序吗? - User taps on UILocalNotification: Can it pass data to the app? 当用户点击iOS中另一个应用程序上的链接时,如何启动我的应用程序? - How can I launch my app when a user taps on a link on another app in iOS? 当用户点击应用中的任何链接时,如何阻止我的ios应用打开网址? - How do i stop my ios app from opening a url when user taps on any link in the app? 跟踪按钮上的水龙头? - Keep track of taps on a button? iPhone可达性-如何在整个应用程序中使用它? - iPhone Reachability - How can I use it across my entire app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM