gpt4 book ai didi

ios - 在 UIWindow 上显示 UIAlertController

转载 作者:行者123 更新时间:2023-11-28 06:53:59 25 4
gpt4 key购买 nike

我有一个 UIWindow 嵌套在我所有的导航 Controller 之上(它是一个可滑动、可拖动的迷你视频播放器)。我正在这样初始化它:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

let player = CustomWindowClass(frame:UIScreen.mainScreen().bounds)
var window: UIWindow? {
set {

}
get {

return player
}
}
}

现在 player 的页面上有一个按钮,应该提示 UIAlertController。我的问题是我无法直接从 UIWindow presentViewController:。我可以使用:

let rootView = UIApplication.sharedApplication().keyWindow?.rootViewController
rootView?.presentViewController(theAlertController, animated: true, completion: nil)

..但它出现在我的 UIWindow 后面。我整天都在寻找如何安全地在我的 UIWindow 上方显示 UIAlertController,但一无所获。有什么建议吗?

最佳答案

UIApplication.sharedApplication().windows 返回的 windows 数组的大小是多少?

我猜它会是 2,数组中的第二个将是您的新窗口。尝试调查返回数组中的每个 window,并尝试在每个窗口上显示 UIAlertViewController 以查看它是否具有预期的效果。

例如,如果有两个 windows 返回:

let controller = application.windows[1].rootViewController as UIViewController
controller.presentViewController(theAlertController, animated: true, completion: nil)

引用:How to present UIAlertView from appDelegate

关于ios - 在 UIWindow 上显示 UIAlertController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34191838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com