我想在当前项目中实现会话时间功能.所以为此我尝试子类化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)
}
}
Run Code Online (Sandbox Code Playgroud)
在app委托中,我做到了这一点
private let baseWindow = BaseWindow()
var window: UIWindow? {
get {
return baseWindow
}
set {}
}
Run Code Online (Sandbox Code Playgroud)
但问题是touchesBegan,touchesEnded并没有得到调用.我无法弄清楚我做错了什么.
我通过调用 .thumbTintColor 来改变 UISlider 的颜色
@IBAction func slider1Master(sender: AnyObject) {
slider1.thumbTintColor = UIColor.orangeColor()}
Run Code Online (Sandbox Code Playgroud)
它有效,但我希望在触摸结束(用户抬起手指)时颜色变回原来的状态。
有没有人有什么建议?谢谢你。