How to prevent status bar from overlapping content with hidesBarsOnSwipe set on UINavigationController?

后端 未结 9 906
灰色年华
灰色年华 2020-12-02 11:10

I\'m trying to use the new feature added in iOS 8 - hiding the navigation bar while user is scrolling the table view (similar to what mobile Safari does). I\'m setting the p

9条回答
  •  执念已碎
    2020-12-02 11:54

    Actually it is pretty easy to do. You just need to connect navigation isNavigationBarHidden property with status bar.

    Objective-C

    - (BOOL)prefersStatusBarHidden {
        return self.navigationController.isNavigationBarHidden;
    }
    

    Swift <= 2.3

    override func prefersStatusBarHidden() -> Bool {
        return navigationController?.navigationBarHidden ?? false
    }
    

    Swift 3.0

    override var prefersStatusBarHidden: Bool {
        return navigationController?.isNavigationBarHidden ?? false
    }
    

    And be sure you have "View controller-based status bar appearance" = "YES" in your application .plist file.

提交回复
热议问题