如何从 UIGesture 获取多点触摸的多个坐标
我有三个手势:2 指点击、3 指点击和4 指点击。我需要相应地获取坐标。
我已尝试以下方法来协调 2 个手指点击,但应用程序不断崩溃:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSArray *twoTouch = [touches allObjects];
UITouch *tOne = [twoTouch objectAtIndex:0];
UITouch *tTwo = [twoTouch objectAtIndex:1];
CGPoint firstTouch = [tOne locationInView:[tOne view]];
CGPoint secondTouch = [tTwo locationInView:[tTwo view]];
NSLog(@"point one: %@", firstTouch);
NSLog(@"point two: %@", secondTouch);
[twoTouch release];
}
I have three gestures: 2-finger tap, 3-finger tap, and 4-finger tap. I need to get coordinates accordingly.
I have tried the following to get the coordinated of 2 fingers tap but app keeps crashing:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSArray *twoTouch = [touches allObjects];
UITouch *tOne = [twoTouch objectAtIndex:0];
UITouch *tTwo = [twoTouch objectAtIndex:1];
CGPoint firstTouch = [tOne locationInView:[tOne view]];
CGPoint secondTouch = [tTwo locationInView:[tTwo view]];
NSLog(@"point one: %@", firstTouch);
NSLog(@"point two: %@", secondTouch);
[twoTouch release];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您的应用程序不会检查是否确实有两次触摸。
如果您用一根手指点击屏幕,您将在“触摸”中获得一次触摸。
尝试这样的事情。
否则,程序崩溃的部分是 [twoTouch objectAtIndex:1],因为 objectAtIndex:1 不存在。
(我知道这是一个非常老的问题,但我还是回答了。)
First of all, your application is not checking if there actually are two touches.
If you tap the screen with one finger you will get one touch in the "touches".
Try something like this.
Otherwise, the part where your program crashes is the [twoTouch objectAtIndex:1] because objectAtIndex:1 doesn't exist.
(I know this is a really old question but I answered it anyways.)