我正在迅速编写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
}
}
但是问题在于它不遵守通话状态栏。如果在打开应用程序之前打开了通话状态栏,则我的视图将从底部显示在屏幕之外。
答案 0 :(得分:0)
在您的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!
})
}