gpt4 book ai didi

ios - 通话中状态栏将 View 推出底部

转载 作者:行者123 更新时间:2023-11-30 10:52:33 27 4
gpt4 key购买 nike

我正在用 swift 编写一个 iOS 应用程序。

我有一个动态启动屏幕,然后是登录页面。

我使用本教程来替换框架: iOS: Root Controller Navigation

class RootViewController: UIViewController {
...
override func viewDidLoad() {
super.viewDidLoad()

addChildViewController(current) // 1
current.view.frame = view.bounds // 2
view.addSubview(current.view) // 3
current.didMove(toParentViewController: self) // 4
}
}

func showLoginScreen() {

let new = UINavigationController(rootViewController: LoginViewController()) // 1
addChildViewController(new) // 2
new.view.frame = view.bounds // 3
view.addSubview(new.view) // 4
new.didMove(toParentViewController: self) // 5
current.willMove(toParentViewController: nil) // 6
current.view.removeFromSuperview()] // 7
current.removeFromParentViewController() // 8
current = new // 9
}
}

但问题是它不遵守通话状态栏。如果在打开应用程序之前打开通话状态栏,我的 View 将从底部显示在屏幕之外。

最佳答案

在您的AppDelegate中使用它:

func application(_ application: UIApplication, willChangeStatusBarFrame newStatusBarFrame: CGRect) {
UIView.animate(withDuration: 0.35, animations: {() -> Void in
var windowFrame: CGRect? = (self.window?.rootViewController as? UINavigationController)?.view?.frame
if newStatusBarFrame.size.height > 20 {
windowFrame?.origin.y = newStatusBarFrame.size.height - 20
// old status bar frame is 20
}
else {
windowFrame?.origin.y = 0.0
}
(self.window?.rootViewController as? UINavigationController)?.view?.frame = windowFrame!
})
}

关于ios - 通话中状态栏将 View 推出底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54308720/

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