info.plist
<key>UIViewControllerBasedStatusBarAppearance</key> <true/>
UIViewController
override var prefersStatusBarHidden: Bool{ return true }
当我使用6p时,可以,但是 iphoneX不能调用,并且StatusBar不隐藏
您需要检查您的视图控制器是否包含在容器中(即 UINavigationController )。如果是这样,整个过程是这样的:
1)将 info.plist 文件中的View controller-based status bar appearance值设置为YES
controller-based status bar appearance
2)在您的子控制器中添加以下代码:
3)添加此扩展名:
// gives control of the status bar appearance to the top controller extension UINavigationController { override open var childViewControllerForStatusBarHidden: UIViewController? { return self.topViewController } }
您已经有了点1和2。相同的逻辑适用于UITabBarController