[英]Display UIAlertController over UIWindow
I have a UIWindow
nested above all of my navigation controllers (it's a swipeable, draggable mini video player). 我的
UIWindow
嵌套在所有导航控制器上方(这是可滑动,可拖动的迷你视频播放器)。 I'm initializing it like this: 我正在这样初始化它:
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
let player = CustomWindowClass(frame:UIScreen.mainScreen().bounds)
var window: UIWindow? {
set {
}
get {
return player
}
}
}
Now that player
has a button on it's page that should prompt a UIAlertController
. 现在,该
player
的页面上有一个按钮,应该会提示一个UIAlertController
。 My problem is that I can't presentViewController:
directly from the UIWindow
. 我的问题是我不能直接从
UIWindow
presentViewController:
。 I can use: 我可以用:
let rootView = UIApplication.sharedApplication().keyWindow?.rootViewController
rootView?.presentViewController(theAlertController, animated: true, completion: nil)
..but it appears behind my UIWindow
. ..但是它出现在我的
UIWindow
后面。 I've been searching all day for how I can safely display the UIAlertController
above my UIWindow
, but have been empty-handed. 我一直在寻找一整天的我怎么能放心地显示
UIAlertController
上面我UIWindow
,但一直两手空空。 Any suggestions? 有什么建议么?
What's the size of the returned array of windows
from UIApplication.sharedApplication().windows
? UIApplication.sharedApplication().windows
返回的windows
数组的大小是多少?
I'm guessing that it will be 2, and the second one in the array will be your new window. 我猜它将是2,而数组中的第二个将是您的新窗口。 Try investigating each
window
in the returned array, and try presenting the UIAlertViewController
on each of those to see if it has the desired effect. 尝试调查返回的数组中的每个
window
,并尝试在每个window
上显示UIAlertViewController
,以查看其是否具有所需的效果。
eg, if there are two windows
returned: 例如,如果返回两个
windows
:
let controller = application.windows[1].rootViewController as UIViewController
controller.presentViewController(theAlertController, animated: true, completion: nil)
Reference: How to present UIAlertView from appDelegate 参考: 如何从appDelegate呈现UIAlertView
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.