为什么 UIView ExclusiveTouch 属性不阻塞?
我正在启动一个带有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自苹果开发者论坛:
From Apple developer forums:
将其放入 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