为什么 UIView 的exclusiveTouch 属性没有阻塞? [英] Why is UIView exclusiveTouch property not blocking?

查看:19
本文介绍了为什么 UIView 的exclusiveTouch 属性没有阻塞?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在启动一个带有 textField 的简单 UIView - 我们称之为 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:].

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

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

Apple 文档说明了 exclusiveTouch:

Apple documentation says about exclusiveTouch:

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

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.

我假设相同的窗口"意味着相同的 UIWindow,其中我只有一个.

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

问题是,当我实例化我的 orderSetNameView,将其添加为子视图,并设置 exclusiveTouch = YES 时,我的应用程序的所有其他视图中都会发生触摸事件,即其他视图中的触摸事件未按预期阻止.

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;

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

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

推荐答案

来自 Apple 开发者论坛:

From Apple developer forums:

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

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

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.

这篇关于为什么 UIView 的exclusiveTouch 属性没有阻塞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆