ios - 使用 spritekit 检测释放快速滑动时的坐标

标签 ios swift sprite-kit uigesturerecognizer swipe-gesture

<分区>

您好,如果有人可以帮助我,那就太好了!

我需要获取滑动的坐标。我可以从 locationInNode 等获取初始触摸的坐标,但是我们如何获取滑动释放点的坐标?

func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    touched = true

    for touch in touches {
        location = touch.locationInNode(self)
        print(location)
    }
}

这就是我获取初始坐标的方式,我也为 touchesMoved 这样做了

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

使用此代码,它不会打印触摸时释放的最终坐标。

基本上我想用坐标来锻炼第一次触摸和释放滑动点之间的距离。 感谢您的帮助!!

最佳答案

捕获滑动的状态,从beginended:

let point: CGPoint = recognizer.location(in: recognizer.view!)
if recognizer.state == .began {
    print(NSCoder.string(for: point))
}
else if recognizer.state == .ended {
    print(NSCoder.string(for: point))
}

关于ios - 使用 spritekit 检测释放快速滑动时的坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34939908/

相关文章:

arrays - iOS/Swift : How to indicate the first position of the $0 in the . 第一个索引? 'Cannot convert value of type ' Any' 到预期参数类型 'String' '

swift - 如何复制具有物理属性的 Sprite 然后将其添加到场景中?

ios - 条件绑定(bind)的初始化程序必须具有 Optional 类型,而不是 'UITouch'

swift - 如何使物理体粘附在节点 anchor 上

iphone - 将单 View 应用程序合并到 Storyboard

ios - 快速为所有屏幕尺寸制作按钮动画

iOS Swift UICollectionView registerNib 可重用 View 不起作用

ios - 隐藏或移动选定的 Cell 并在 UItableView 的 indexPath.row 中加载一个新的自定义 Cell

ios - 如何快速使用滑动手势翻转 x 和 y 轴上的图像?

ios - '[字符串 ]' is not convertible to ' [NSString]'