0

我正在制作一个 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];
}
4

1 回答 1

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;
}
于 2012-08-02T21:49:38.170 回答