在UILongPressGestureRecognizer中获取每次触摸的坐标

时间:2013-03-10 01:45:53

标签: ios objective-c cocoa-touch uigesturerecognizer

我设置了UILongPressGestureRecognizer numberOfTouchesReguired = 2。如何在视图上获得每个手指的连续坐标?

目前我有这个,但它似乎将所有触摸的位置合并为1个坐标。

- (void)handleLongPress:(UILongPressGestureRecognizer *)sender {
    CGPoint locationInView = [sender locationInView:nil];
}

1 个答案:

答案 0 :(得分:8)

请参阅UIGestureRecognizer的文档。它提供了以下方法:

- (void)handleLongPress:(UILongPressGestureRecognizer *)sender {
    if (sender.state == UIGestureRecognizerStateChanged) {
        NSUInteger *touchCount = [sender numberOfTouches];
        for (NSUInteger t = 0; t < touchCount; t++) {
            CGPoint point = [sender locationOfTouch:t inView:sender.view];
        }
    }