touchesBegan多次打电话

时间:2014-11-13 08:56:40

标签: ios swift uitouch

我有一个奇怪的问题, touchesBegan 处理程序被调用超过必要的。 如果我快速点击UIView(UIButton)2次, touchesBegan 被称为 3 次。

我用简单的时间测量解决了这个问题,但我仍然感兴趣的是这种行为的原因是什么?

这是代码(已添加时间检查):

override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
    if let t:UITouch = touches.anyObject() as? UITouch
    {
        if !CGRectContainsPoint(CGRectMake(0, 0, self.frame.width, self.frame.height), t.locationInView(self))
        {
            touchesCancelled(touches, withEvent: event)
        }
    }
}

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    ForCancelTouch = false
    setupButtonGUI(true)
}

override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
    if !ForCancelTouch
    {
        if abs(LastValidTouchesBeganDate.timeIntervalSinceNow) > DelayBetweenFastTapping
        {
            NSNotificationCenter.defaultCenter().postNotificationName(SBDCNotificationNameActionSTBMakeOneCommand, object: self, userInfo: ["tag":self.tag])
            LastValidTouchesBeganDate = NSDate()
        }
    }
    setupButtonGUI(false)
}

override func touchesCancelled(touches: NSSet!, withEvent event: UIEvent!) {
    ForCancelTouch = true
    setupButtonGUI(false)
}

1 个答案:

答案 0 :(得分:1)

嗯 - 似乎问题只发生在iOS模拟器中用鼠标点击/测试时!它看起来像是一个iOS模拟器错误。