iphone - 为什么 UIView ExclusiveTouch 属性不阻塞?

标签 iphone ipad uiview

我正在启动一个带有 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/

相关文章:

ios - Swift - 从远程 URL 下载视频并将其保存在相册中

Swift View Controller 不会关闭

ios - 组合不同的 UIView 类

iphone - iOS 开发 : How can I preload a view controller before pushing it onto the navigation stack?

iOS - ScrollView 上的多种背景颜色

iphone - NSFetchedResultsSectionInfo 对于它有多少个对象与自己不一致

ios - 如何在 UISearchDisplayController 的 UISearchBar 中更改 "Cancel"按钮、 "No Results"标签的字符串?

iphone - 配置构建阶段的编译源

iphone - 新的 Xcode 目标 : changing configuration settings/preprocessor macros

iphone - 为什么我的 UINavigationBar 在我运行我的应用程序时会改变颜色?