gpt4 book ai didi

ios - touchesBegan 多次调用

转载 作者:行者123 更新时间:2023-11-29 02:30:48 26 4
gpt4 key购买 nike

我有一个奇怪的问题,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)
}

最佳答案

好吧 - 似乎只有在 iOS 模拟器中用鼠标单击/测试时才会出现此问题!看起来这是一个 iOS 模拟器错误。

关于ios - touchesBegan 多次调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26904795/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com