【发布时间】:2016-01-06 07:19:12
【问题描述】:
我有一个类PanAndZoomView,它继承自UIView,负责我正在处理的iOS 应用程序中的一个屏幕。该项目还有其他开发人员,应用程序中的许多其他屏幕不是我的,PanAndZoomView 不是入口屏幕。
I have multiple touch enabled 用于情节提要中的视图:
我在下面的方法中使用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 类,它可以毫无问题地看到多次触摸。
为什么忽略第二次触摸?
如何诊断我的问题?
【问题讨论】:
-
而
touches只包含一个UITouch? -
是的 - 当我在循环中添加
print并枚举touches时,只有一个成员 -
您可以尝试在您的函数中调用
super.touchesBegan(touches, withEvent: event)吗? -
谢谢@Francescu,我刚刚尝试过,但没有效果。
-
抱歉没用!我猜你确保日志打印
multipleTouchEnabled = true?我看不出你的代码有什么问题。我的建议是创建一个空的UIView子类并仅添加具有空实现的touchesBegan函数(仅在内部print)。如果可行,则逐个函数添加代码以查看哪个部分的错误。