检测3个手指触摸整个应用程序而不影响子视图

时间:2012-08-02 20:54:08

标签: ios uiview uigesturerecognizer uitouch

我正在制作一个iPad应用程序,您可以在整个屏幕上随时用3个手指轻扫/平移(取消操作) 它正在使用UISwipeGestureRecognizer或UIPanGestureRecognizer,但我手指下的子视图(例如UITableView或UIScrollview)接收到触摸并移动。我不想要的。

我的想法是在整个应用程序的顶部放置透明的UIView,以便将触摸转发到其他视图。我用hitTest尝试了一些东西,但我觉得我不太懂,因为触摸的返回次数不对,需要时间......

非常感谢你能帮助我:)

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    if (event.type == UIEventTypeTouches) {
        if (event.allTouches.count >= 2) {
            return self;
        }
    }
    return [super hitTest:point withEvent:event];
}

1 个答案:

答案 0 :(得分:0)

我认为你必须使用

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer

UIGestureRecognizer的委托来定义哪些手势同时有效。

例如:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer

    NSLog(@"gestRecogn: %@ otherGestRec: %@",[[gestureRecognizer class] className],[[otherGestureRecognizer class] className]);

    if ([[[gestureRecognizer class] className] isEqualToString:@"UIScrollViewPanGestureRecognizer"] && [[[otherGestureRecognizer class] className] isEqualToString:@"UILongPressGestureRecognizer"]) {
        return FALSE;
    }
    if ([[[gestureRecognizer class] className] isEqualToString:@"UILongPressGestureRecognizer"] && [[[otherGestureRecognizer class] className] isEqualToString:@"UIScrollViewPanGestureRecognizer"]) {
        return FALSE;
    }
    return TRUE;
}