第二次触摸被忽略

时间:2016-01-06 07:19:12

标签: ios swift

我有一个类PanAndZoomView,它继承自UIView并负责我正在处理的iOS应用中的一个屏幕。项目中还有其他开发人员,应用程序中的许多其他屏幕都不是我的,而且PanAndZoomView不是输入屏幕。

对于故事板中的视图,

I have multiple touch enabled

xcode screenshot

我用以下方法中的print语句检查

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    print("TouchesBegan, multipleTouchEnabled = \(self.multipleTouchEnabled)")
    let newTouches:Set<UITouch> = touches.subtract(self.touchesBeingTracked)
    for touch:UITouch in newTouches {
        self.initialTouches[touch] = touch.locationInView(self)
        self.initialScale = self.contentsView.transform.a
        self.initialTranslation = CGVector(dx: self.contentsView.transform.tx, dy: self.contentsView.transform.ty)
    }
    self.touchesBeingTracked.unionInPlace(touches)
    self.touchesBeingTrackedPeakCount = touchesBeingTracked.count
    self.segmentationView.containerTouchesBegan(touches, withEvent: event)
}

然而PanAndZoomView只注册我的第一次触摸,即上面的方法只会触发一次,无论我触摸屏幕的手指多少。

我的方法遵循Apple's documentation,并且我在另一个项目中使用相同的PanAndZoomView类,在这个项目中,它可以毫无问题地看到多个触摸。

为什么忽略第二次触摸?

如何诊断我的问题?

1 个答案:

答案 0 :(得分:0)

子视图存在问题。

虽然处理多点触控事件的UIViewPanAndZoomView)在故事板中标记为“启用多点触控”,但其两个子视图却没有。将它们标记为启用多点触控可以修复它,以便现在PanAndZoomView可以进行第二次触摸。

相关问题