iDevelopper / PBRevealViewController

A UIViewController subclass for revealing a left and/or right view controller above or below a main view controller.
MIT License
80 stars 16 forks source link

preferredStatusBarStyle not called in main view controller #58

Closed kirand777 closed 5 years ago

kirand777 commented 5 years ago

I think, childViewControllerForStatusBarStyle and childViewControllerForStatusBarHidden should be redefined so status bar can be changed in main view controller.

iDevelopper commented 5 years ago

As you can subclass PBRevealViewController you can override these properties by yourself.

For example, assume your main view controller is a UINavigationController subclass, and you want to hide the status bar:

class RevealViewController: PBRevealViewController, PBRevealViewControllerDelegate {

    override var childForStatusBarHidden: UIViewController? {
        guard let mainViewController = self.mainViewController as? UINavigationController else {return nil}
        return mainViewController.topViewController
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        self.setNeedsStatusBarAppearanceUpdate()
    }
}

And in your main view controller, the top view controller, override:

    override var prefersStatusBarHidden: Bool {
        return true
    }

You have to set the "View controller-based status bar appearance" key to YES in your Info.plist too.