Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

swift - iphoneX not call prefersStatusBarHidden

info.plist

<key>UIViewControllerBasedStatusBarAppearance</key>
    <true/>

UIViewController

override var prefersStatusBarHidden: Bool{
        return true
   }

when i use 6p ,it's ok but
iphoneX ,it's can't call and StatusBar not hidden

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to check if your view controller is included in a container (i.e. UINavigationController). If that is the case, the full procedure is this:

1) Set the View controller-based status bar appearance value in info.plist file to YES

2) In your child controller add this code:

override var prefersStatusBarHidden: Bool{
        return true
   }

3) Add this extension:

// gives control of the status bar appearance to the top controller
extension UINavigationController {
    override open var childViewControllerForStatusBarHidden: UIViewController? {
        return self.topViewController
    }
}

You already have point 1 and 2. Same logic applies to UITabBarController


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...