我想在我当前的项目中实现会话时间功能。因此,为此我试图继承UIWindow
和覆盖touchesBegan
andtouchesEnded
方法。
class BaseWindow: UIWindow {
convenience init() {
self.init(frame: UIScreen.mainScreen().bounds)
}
private var sessionTimeOutTimer: NSTimer?
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
sessionTimeOutTimer?.invalidate()
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
sessionTimeOutTimer = NSTimer.scheduledTimerWithTimeInterval(60, target: CIAppManager.sharedManger(), selector: #selector(CIAppManager.sessionTimeOut), userInfo: nil, repeats: false)
}
}
在应用程序委托中,我这样做了
private let baseWindow = BaseWindow()
var window: UIWindow? {
get {
return baseWindow
}
set {}
}
但问题是touchesBegan
并且touchesEnded
没有被调用。我无法弄清楚我做错了什么。