为什么 UIView ExclusiveTouch 属性不阻塞?

发布于 2024-09-27 15:52:16 字数 933 浏览 1 评论 0原文

我正在启动一个带有 textField 的简单 UIView - 让我们称之为 orderSetNameView - 点击按钮即可。我希望使此视图成为模态视图,但不使用

[UIViewController PresentModalViewContoller:animated:]

看来我可以简单地设置 textInputView.exclusiveTouch = YES 来实现这一点。

Apple 文档介绍了 exclusiveTouch

一个布尔值,指示接收器是否处理触摸事件 只。如果是,接收者会阻止同一区域中的其他视图 窗口接收触摸事件;否则,它不会。这 默认值为“否”。

我假设“相同的窗口”意味着相同的 UIWindow,其中我只有一个。

问题是,当我实例化 orderSetNameView,将其添加为子视图并设置 exclusiveTouch = YES 时,触摸事件发生在我的应用程序的所有其他视图中,即其他视图中的触摸事件不会被阻止正如预期的那样。

    // ....

    [self.view addSubview:self.orderSetNameView];
    [self.orderSetNameView openWithAnimationForAnimationStyle:kMK_AnimationStyleScaleFromCenter];
}

// Set as modal
self.orderSetNameView.exclusiveTouch = YES;

orderSetNameView 不应该阻止所有其他视图中的触摸事件吗?我缺少什么?

I am launching a simple UIView with a textField - let's call it orderSetNameView - upon a button tap. I wish to make this view modal, but without using a

[UIViewController presentModalViewContoller:animated:].

It seems I could simply set textInputView.exclusiveTouch = YES to achieve that.

Apple documentation says about exclusiveTouch:

A Boolean value indicating whether the receiver handles touch events
exclusively. If YES, the receiver blocks other views in the same
window from receiving touch events; otherwise, it does not. The
default value is NO.

I assume "same window" means same UIWindow, of which I have only one.

The problem is that when I instantiate my orderSetNameView, add it as a subview, and set exclusiveTouch = YES, touch events happen in all other views of my app, i.e., touch events in other views are not blocked as expected.

    // ....

    [self.view addSubview:self.orderSetNameView];
    [self.orderSetNameView openWithAnimationForAnimationStyle:kMK_AnimationStyleScaleFromCenter];
}

// Set as modal
self.orderSetNameView.exclusiveTouch = YES;

Shouldn't orderSetNameView block touch events in all other views? What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独﹏钓一江月 2024-10-04 15:52:16

来自苹果开发者论坛:

exclusiveTouch 仅在独占触摸视图中存在活动触摸时阻止其他视图中的触摸。也就是说,如果您将手指放在独占触摸视图中,则在抬起第一根手指之前,触摸不会在其他视图中开始。如果 ExclusiveTouch 视图中当前没有触摸,则它不会阻止在其他视图中启动触摸。

要真正使此视图成为屏幕上唯一可以接收触摸的内容,您需要在其他所有视图之上添加另一个视图以捕获其余的触摸,或者在您的某个位置子类化视图。层次结构(或您的 UIWindow 本身)并覆盖 hitTest:withEvent: 以在文本视图可见时始终返回文本视图,或者对于不在文本视图中的触摸返回 nil。

From Apple developer forums:

exclusiveTouch only prevents touches in other views during the time in which there's an active touch in the exclusive touch view. That is, if you put a finger down in an exclusive touch view touches won't start in other views until you lift the first finger. It does not prevent touches from starting in other views if there are currently no touches in the exclusiveTouch view.

To truly make this view the only thing on screen that can receive touches you'd need to either add another view over top of everything else to catch the rest of the touches, or subclass a view somewhere in your hierarchy (or your UIWindow itself) and override hitTest:withEvent: to always return your text view when it's visible, or to return nil for touches not in your text view.

小女人ら 2024-10-04 15:52:16

将其放入 AppDelegate 或其他文件中。使用这一次。

// 禁用多点触摸

UIView.appearance().isExclusiveTouch = true

UIButton.appearance().isExclusiveTouch = true

Put this in AppDelegate or another file. Use this single time.

// Multi Touch Disable

UIView.appearance().isExclusiveTouch = true

UIButton.appearance().isExclusiveTouch = true

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文