swift - 如何在 Swift 中从 UIApplication 中删除窗口

标签 swift xcode uiwindow uiapplication

点击按钮时,我使用以下代码移动到另一个 View Controller 。

var window: UIWindow?
window = UIWindow.init(frame: UIScreen.main.bounds)
window?.autoresizesSubviews = true
window?.autoresizingMask = [.flexibleWidth, .flexibleHeight]
let trackingViewController = LoginCameraViewController.init(screen: 
.main)
window?.rootViewController = trackingViewController
window?.addSubview((trackingViewController?.view)!)
window?.makeKeyAndVisible()
window?.layoutSubviews()

每次单击按钮,都会向应用程序添加一个新窗口。我想删除添加的最新窗口。 使用以下代码可以知道应用程序中存在的窗口数。

let windowz = UIApplication.shared.windows
print("subviews",windowz)

最佳答案

我认为您对 iOS 中的导航概念有误。窗口就像一个根对象,其中出现了 ViewController。因此,您首先要寻找的解决方案可能是 UINavigationController

Apple Documentation on Navigation

关于swift - 如何在 Swift 中从 UIApplication 中删除窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52097866/

相关文章:

iphone - 在 UITableView 的顶部和底部添加按钮

swift - 访问字典中的字典并将其分配给变量

ios - 代码签名错误。添加新的mac进行开发

ios5 - iOS : Programmatically creating UIWindow results in wrong position

ios - 以编程方式设置为 Root View Controller 时, View Controller 无法正确显示 subview

ios - Swift:如何在单击提交按钮时更改 UIButton 图像

ios - 无法获得 supportedInterfaceOrientationsForWindow 以使用 Swift 1.2

ios - 按类别及其子元素填充列表

ios - 如果用户回答传入的 iMessage,WKWebView 会崩溃

Swift iOS - 如何将 subview 添加到窗口的中心?