我正在移植一个具有内置专有手势系统的Windows touch应用程序,其中一个要求是我必须使用它。该手势系统采用一系列x,y点(每个触点一个点),并从这些原始点推断出手势。
我之前从未在iOS上做过这个,并且想知道最好的(只有???)方法是做什么的。
答案 0 :(得分:0)
您需要使用Touches开始:
- (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
}
答案 1 :(得分:0)
在swift:
确保您的ViewController实现了UIGestureRecognizerDelegate:
class MyViewController: UIViewController, UIGestureRecognizerDelegate{...}
在ViewController中覆盖以下内容:
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
}
}