ios-获取原始多点触摸x、y位置
我正在移植一个具有内置专有手势系统的windows touch应用程序,其中一个要求是我必须使用它。该手势系统获取一系列x、y点(每个接触点一个),并从这些原始点推断手势ios-获取原始多点触摸x、y位置,ios,Ios,我正在移植一个具有内置专有手势系统的windows touch应用程序,其中一个要求是我必须使用它。该手势系统获取一系列x、y点(每个接触点一个),并从这些原始点推断手势 我以前从未在iOS中这样做过,我想知道最好的(唯一的?)方法是什么。您需要使用触摸屏: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject];
我以前从未在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
}
迅速:
确保ViewController实现UIgestureRecognitzerDelegate:
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
}
}
override func touchsbegined(touchs:Set,withEvent-event:UIEvent){
super.touchsbegind(touchs,withEvent:event)
如果让触摸:UITouch=touch.first as?UITouch{
让touchLocation=touch.locationInView(self.view)作为CGPoint
touchLocation.x
触动位置
}
}
覆盖func touchesEnded(触摸:设置,withEvent事件:UIEvent){
//手势结束时
}
覆盖功能触摸移动(触摸:设置,withEvent事件:UIEvent){
如果让触摸:UITouch=touch.first as?UITouch{
让touchLocation=touch.locationInView(self.view)作为CGPoint
touchLocation.x
触动位置
}
}