简体   繁体   中英

touchesBegan called many times

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)
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM