Swift SpriteKit 3D触控和移动触控

Swift SpriteKit 3D触控和移动触控,swift,touchesmoved,3dtouch,Swift,Touchesmoved,3dtouch,我最近将我的游戏版本发送到TestFlight进行内部测试。 我的朋友注意到,在他的iphone6s上加上拍摄控件不能正常工作 控件如下所示 1) 屏幕左半部分=跳转 2) 屏幕右半部分=拍摄 3) 滑动并按住屏幕右半部分=开始慢动作 现在,在我的接触开始方法中,我的拍摄有一点延迟,所以如果称为接触移动,它将取消拍摄并开始慢速移动。 这似乎是导致3D触摸手机出现问题的原因 深入研究后,我发现了这篇文章 它基本上说明在3D触控设备上,触控移动方法会自动调用 On 3D Touch capab

我最近将我的游戏版本发送到TestFlight进行内部测试。 我的朋友注意到,在他的iphone6s上加上拍摄控件不能正常工作

控件如下所示

1) 屏幕左半部分=跳转

2) 屏幕右半部分=拍摄

3) 滑动并按住屏幕右半部分=开始慢动作

现在,在我的接触开始方法中,我的拍摄有一点延迟,所以如果称为接触移动,它将取消拍摄并开始慢速移动。 这似乎是导致3D触摸手机出现问题的原因

深入研究后,我发现了这篇文章

它基本上说明在3D触控设备上,触控移动方法会自动调用

  On 3D Touch capable devices, touch pressure changes cause     
   touchesMoved:withEvent: to be called for all apps running on iOS   
   9.0. When running iOS 9.1, the method is called only for apps  
   linked with the iOS 9.0 (or later) SDK.

    Apps should be prepared to receive touch move events with no   
    change in the x/y coordinates. "
这似乎解释了为什么我的朋友有问题,如果总是称为“触动移动”,它将取消拍摄并启动慢速移动,即使他没有在屏幕上滑动

所以我的问题是

1) 你能在SpriteKit游戏中禁用3D触摸吗

2) 这是虫子吗

3) 在3D触控设备上使用正确移动的触控还有其他方法吗

4) 或者,我可以使用手势识别器来模拟我当前在触摸中使用的滑动和保持功能


感谢您的帮助

在尝试了其他各种不起作用的东西后,包括UISweepGestureRecognitzer子类,我终于找到了答案

答案实际上就在我在问题中链接的那篇帖子上,正盯着我的脸

解决方案是创建一个属性

var startingTouchLocation: CGPoint?
而不是你设置的属性

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    for touch in touches {
        let location = touch.locationInNode(self)

        /// Set starting touch. this is for 3d touch enabled devices, see touchesMoved method below
        startingTouchLocation = location


        ....
     }
 }
覆盖函数触摸开始(触摸:设置,withEvent事件:UIEvent?){
接触{
let location=touch.locationInNode(自)
///设置起始触控。这适用于启用3d触控功能的设备,请参阅下面的触控移动方法
startingTouchLocation=位置
....
}
}
然后添加一个签入触摸移动以从该方法返回,直到触摸实际移动为止

 override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
    for touch in touches {
        let location = touch.locationInNode(self)

        /// WAY 1 - Check if touch moved because on 3d touch devices this method gets called on a force touch.
        guard location != startingTouchLocation else { return }

        // Your code
        ...

        /// WAY 2 - Add a min distance for the finger to travel in any direction before calling touches moved code
        let minValue: CGFloat = 30
        guard let startingLocation = startingLocation else { return }

        guard currentLocation.y < startingLocation.y - minValue ||
        currentLocation.y > startingLocation.y + minValue ||
        currentLocation.x < startingLocation.x - minValue ||
        currentLocation.x > startingLocation.x + minValue else { return  false }

       // Your code 
       ....
     }
  }
覆盖功能触摸移动(触摸:设置,带事件:UIEvent?){
接触{
let location=touch.locationInNode(自)
///方法1-检查触摸是否移动,因为在3d触摸设备上,强制触摸会调用此方法。
守卫位置!=开始触摸位置其他{return}
//你的代码
...
///方式2-在调用代码之前,为手指在任何方向上移动添加一个最小距离
设minValue:CGFloat=30
guard let startingLocation=startingLocation else{return}
保护电流位置.y<启动位置.y-最小值||
currentLocation.y>startingLocation.y+minValue||
currentLocation.xstartingLocation.x+minValue else{return false}
//你的代码
....
}
}

这只是一个快速建议,让我们看看演示机器人示例应用程序,看看在iPhone 6S的示例中是否会出现类似的问题。谢谢您的建议。我在项目中经常使用DemoBots示例。我刚刚检查过,他们使用了两次“touchesMoved…”方法。然而,两者都属于SKSpriteNodes的子类,所以我想知道这是否有区别。我没有3d触摸设备,所以测试起来很糟糕。我也是。您可以通过OTA分发(例如TestFlight)将演示机器人分发给您的朋友进行测试,作为最后手段。是的,谢谢,我可能会尝试一下。列表中描述的方式似乎是一个bug。我现在正在考虑其他选择。再次感谢,因为你感兴趣,我发布了一个关于如何解决这个问题的答案。再次感谢你的帮助我也有同样的问题。在iphone6s上,touchesMoved方法在touchesbeated被调用后立即被调用。我们需要小心。是的,同样的问题,这解决了!iPhoneX和更高版本运行良好,但在8和更低版本上,它多次移动,阻碍了我的逻辑。