标签: touchesended

UIWindow子类:触摸事件未被触发

我想在当前项目中实现会话时间功能.所以为此我尝试子类化UIWindow并覆盖touchesBegantouchesEnded方法.

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并没有得到调用.我无法弄清楚我做错了什么.

uiwindow touchesbegan ios swift touchesended

2
推荐指数
1
解决办法
835
查看次数

触摸结束时如何更改 UISlider 拇指外观

我通过调用 .thumbTintColor 来改变 UISlider 的颜色

@IBAction func slider1Master(sender: AnyObject) {

    slider1.thumbTintColor = UIColor.orangeColor()}
Run Code Online (Sandbox Code Playgroud)

它有效,但我希望在触摸结束(用户抬起手指)时颜色变回原来的状态。

有没有人有什么建议?谢谢你。

uislider swift touchesended

0
推荐指数
1
解决办法
2330
查看次数

标签 统计

swift ×2

touchesended ×2

ios ×1

touchesbegan ×1

uislider ×1

uiwindow ×1