Swift 全局监控用户是否有点击操作

  1. 给window添加手势
在application(_ application: , didFinishLaunchingWithOptions launchOptions: ?)里面
  // 添加手势
  let tapGesture = UITapGestureRecognizer(target: self, action: nil)
  tapGesture.delegate = self
  window?.addGestureRecognizer(tapGesture)
  1. 实现代理方法
extension AppDelegate: UIGestureRecognizerDelegate{
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        // User tapped on screen, do whatever you want to do here.
        print("点击了屏幕")
        return false
    }
}

你可能感兴趣的:(Swift 全局监控用户是否有点击操作)