使用 spritekit 检测释放滑动 swift 时的坐标
Detect coordinates on release of a swipe swift with spritekit
你好,如果有人能帮助我,那就太好了!
我需要获取滑动的坐标。我可以从 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)
}
使用此代码,它不会打印触摸时释放的最终坐标。
基本上我想用坐标来锻炼第一次触摸和释放滑动时的点之间的距离。
感谢您的帮助!!
抓取滑动状态,从began
到ended
:
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))
}
-(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);
}
}
你好,如果有人能帮助我,那就太好了!
我需要获取滑动的坐标。我可以从 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)
}
使用此代码,它不会打印触摸时释放的最终坐标。
基本上我想用坐标来锻炼第一次触摸和释放滑动时的点之间的距离。 感谢您的帮助!!
抓取滑动状态,从began
到ended
:
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))
}
-(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);
}
}