0
我正在移植具有内置专有手势系统的windows touch应用程序,并且其中一个要求是我必须使用它。这个手势系统需要一系列x,y点(每个触摸点一个点),并从这些原始点推断手势。ios - 获取原始多点触控x,y位置
我从来没有在iOS上做过这件事,并想知道最好的(唯一的)方法是做什么。
我正在移植具有内置专有手势系统的windows touch应用程序,并且其中一个要求是我必须使用它。这个手势系统需要一系列x,y点(每个触摸点一个点),并从这些原始点推断手势。ios - 获取原始多点触控x,y位置
我从来没有在iOS上做过这件事,并想知道最好的(唯一的)方法是做什么。
你需要使用倒是开始:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self];
touchLocation.x; // x coord
touchLocation.y; // y coord
}
在SWIFT:
确保您的视图控制器实现UIGestureRecognizerDelegate:
class MyViewController: UIViewController, UIGestureRecognizerDelegate{...}
的视图控制器内覆盖以下内容:
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
if let touch: UITouch = touches.first as? UITouch{
let touchLocation = touch.locationInView(self.view) as CGPoint
touchLocation.x
touchLocation.y
}
}
override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
//When gesture ends
}
override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
if let touch: UITouch = touches.first as? UITouch{
let touchLocation = touch.locationInView(self.view) as CGPoint
touchLocation.x
touchLocation.y
}
}