【发布时间】:2016-08-31 15:51:27
【问题描述】:
我想在我当前的项目中实现会话时间功能。因此,我试图继承 UIWindow 并覆盖 touchesBegan 和 touchesEnded 方法。
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 没有被调用。我无法弄清楚我做错了什么。
【问题讨论】:
-
也许这个项目会对你有所帮助:github.com/marqeta/mqtimeout
-
请向我们展示您的整个 app delegate 文件,因为我对
private let baseWindow = ...行的感觉非常糟糕,这似乎没有任何合理的用途,所以,请,整个文件会更健谈。
标签: ios swift uiwindow touchesbegan touchesended