- 給window添加手勢
在application(_ application: , didFinishLaunchingWithOptions launchOptions: ?)里面
// 添加手勢
let tapGesture = UITapGestureRecognizer(target: self, action: nil)
tapGesture.delegate = self
window?.addGestureRecognizer(tapGesture)
- 實現(xiàn)代理方法
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
}
}