我正在启动一个带有 textField
的简单 UIView
- 让我们称之为 orderSetNameView
- 点击按钮即可。我希望使该 View 成为模态视图,但不使用
[UIViewController PresentModalViewContoller:animated:]
。
看来我可以简单地设置textInputView.exclusiveTouch = YES
来实现这一点。
Apple 文档介绍了 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.
我假设“相同的窗口”意味着相同的 UIWindow,其中我只有一个。
问题是,当我实例化 orderSetNameView,将其添加为 subview 并设置 exclusiveTouch = YES
时,触摸事件发生在我的应用程序的所有其他 View 中,即其他 View 中的触摸事件没有按预期被阻止。
// ....
[self.view addSubview:self.orderSetNameView];
[self.orderSetNameView openWithAnimationForAnimationStyle:kMK_AnimationStyleScaleFromCenter];
}
// Set as modal
self.orderSetNameView.exclusiveTouch = YES;
orderSetNameView
不应该阻止所有其他 View 中的触摸事件吗?我错过了什么?
最佳答案
来自 Apple 开发者论坛:
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.
关于iphone - 为什么 UIView ExclusiveTouch 属性不阻塞?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3946147/