【问题标题】:Detect 3 fingers touch in the whole app without affecting the subviews在不影响子视图的情况下检测整个应用程序中的 3 根手指触摸
【发布时间】:2012-08-02 20:54:08
【问题描述】:

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

【问题讨论】:

    标签: ios uiview uigesturerecognizer uitouch


    【解决方案1】:

    我认为你必须使用

    - (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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-13
      • 1970-01-01
      • 2022-10-25
      • 1970-01-01
      • 2016-04-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多