【问题标题】:Detect coordinates on release of a swipe swift with spritekit [closed]使用 spritekit 检测释放滑动 swift 时的坐标 [关闭]
【发布时间】:2016-01-22 05:54:23
【问题描述】:

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

我需要获取滑动的坐标。我可以从 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)
    }

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

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

【问题讨论】:

  • @Elliott Frisch 如果您能帮助我,那就太好了,因为我刚刚提供了我的问题的更多细节

标签: ios swift sprite-kit uigesturerecognizer swipe-gesture


【解决方案1】:

捕获滑动状态,从beganended

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))
}

【讨论】:

  • rashwan 非常感谢!!!
  • @prival,很高兴为您提供帮助!
  • 我不知道把你的代码放在哪里,我试过在视图下加载,并启动 UIGestureRecognizer 但它一直返回 0,0 作为坐标@Rashwan L
  • @prival 将它放在您的 UIGesture 函数中。 let swipe = UITapGestureRecognizer(target: self, action: "myFunc"); self.view.userInteractionEnabled = true。例如,将其放在myFunc 中。
【解决方案2】:
-(IBAction)swipe:(UIGestureRecognizer*)sender
{
    UIView *view1 = sender.view;

    if (sender.state == UIGestureRecognizerStateEnded) {
           CGPoint touchUpPoint = [sender locationInView:view1];
        NSLog(@"x=%f, y=%f",touchUpPoint.x,touchUpPoint.y);
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-05
    • 1970-01-01
    相关资源
    最近更新 更多