问题描述
最近我一直在想,iOS 应用只有一个 UIWindow
.创建另一个 UIWindow
并将其放在屏幕上似乎不是问题.
Recently I've been wondering about the fact that that an iOS app only has one UIWindow
.
It does not seem to be an issue to create another UIWindow
and place it on screen.
我的问题有点含糊,但我很感兴趣:
My question is kind of vague, but I'm interested in:
- 我可以通过第二个
UIWindow
实现哪些其他方式无法实现的目标? - 使用多个
UIWindow
实例时会出现什么问题? - 我看到人们使用第二个
UIWindow
在 iPhone 上显示类似弹出窗口的视图.这是一个好方法吗?为什么?为什么不呢? - 是否还有其他示例表明拥有另一个
UIWindow
非常有意义?
- What could I potentially achieve with a second
UIWindow
that cannot be done in other ways? - What can go wrong when using multiple
UIWindow
instances? - I have seen that people use a 2nd
UIWindow
to display popover like views on iPhone. Is this a good way of doing it? Why? Why not? - Are there other examples where it is making perfectly sense to have another
UIWindow
?
这并不是我错过了什么.我从来没有觉得需要创建另一个 UIWindow
实例,但也许它可以做一些我不知道的惊人事情!:-)
It's not that I'm missing something. I have never felt the need to create another UIWindow
instance but maybe it would allow doing amazing things I'm not aware of! :-)
我希望它可以帮助我解决这个问题:我需要在当前显示的任何内容上添加封面视图".如果已经存在一个或多个模态控制器,它也应该工作.如果我将 UIView
添加到根控制器的视图中,模态控制器位于顶部,弹出框控制器也是如此.如果我以模态方式呈现封面视图并且已经有一个模态控制器,则只会覆盖屏幕的一部分.
I'm hoping that it might help me solve this problem:
I need to add a "cover view" over whatever is currently displayed. It should also work if there are already one or more modal controllers presented. If I add a UIView
to the root controller's view, the modal controllers sit on top, so do the popover controllers.
If I present the cover view modally and there is already a modal controller, only part of the screen is covered.
推荐答案
一个 UIWindow
可以浮动在其他 UI 元素(如系统键盘)之上.
A UIWindow
can float above other UI elements like the system keyboard.
解决您的最后一段:制作一个与您的主窗口具有相同框架的 UIWindow
.将其 windowLevel
属性设置为 UIWindowLevelStatusBar
.将其 hidden
属性设置为 NO
.
To address your last paragraph: Make a UIWindow
with the same frame as your main window. Set its windowLevel
property to UIWindowLevelStatusBar
. Set its hidden
property to NO
.
这篇关于向 iOS 应用程序添加另一个 UIWindow 的优点、问题、示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!