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

查看:79
本文介绍了为什么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天全站免登陆