【问题标题】:Second touch is ignored第二次触摸被忽略
【发布时间】: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)。如果可行,则逐个函数添加代码以查看哪个部分的错误。

标签: ios swift


【解决方案1】:

这是子视图的问题。

尽管处理多点触控事件的UIView(我的代码中的PanAndZoomView)在情节提要中被标记为“启用多点触控”,但它的两个子视图却没有。将它们标记为启用多点触控可以修复它,以便 PanAndZoomView 现在获得第二次触控。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多