touchesBegan called many times

531 views Asked by At

I have strange issue with touchesBegan handler being called more than necessary. If I tapped the UIView (UIButton) fast 2 times, touchesBegan was called 3 times.

I solved the issue with simple time measurement but I am still interested what would be the reason for this kind of behaviour?

Here is the code (with already added time-checking):

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

There are 1 answers

0
sabiland On

Well - it seems the issue happens ONLY when clicking/testing with mouse inside iOS simulator! It looks like it is an iOS simulator bug.