【问题标题】:touchesBegan not working for multiple touchestouchesBegan 不能用于多次触摸
【发布时间】:2015-07-29 04:02:27
【问题描述】:

我的 touchesBegan 对于发生的每个不同的触摸事件都能正常工作,但我同时触摸两个不同的位置时除外。我总是必须先抬起一根手指,然后才能放下另一根手指。有没有办法让touchesBegan(并希望touchesMoved)同时为两个不同的触摸工作?在我的项目中,我有一把剑,如果你点击手柄,它会平移剑,如果你点击刀片,它会旋转剑,但是如果你同时点击两者,剑就会飞过屏幕.

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
    /* Called when a touch begins */
    for touch in (touches as! Set<UITouch>) {
        let location = touch.locationInNode(self)
        dx = location.x - Handle.position.x
        dy = location.y - Handle.position.y
        locationAngle = atan2(dy, dx)
        if (HandleTouch.containsPoint(location)){
            touchedHandle = true
        }
        else if (BladeTouch.containsPoint(location)){
            touchedBlade = true
        }
    }
}

【问题讨论】:

    标签: xcode swift touch-event touchesbegan


    【解决方案1】:

    确保您的视图的 multipleTouchEnabled 属性设置为 true,您可以在代码中或使用 Interface Builder 中的“多点触控”复选框来执行此操作。

    【讨论】:

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