Search code examples
swiftuikit

iOS 14 display status bar in landscape


Since iOS 8, status bar is hidden in landscape by default, I want to make it visible. I created a new empty project and tried several things from other topics but none of these work:

  1. First solution I tried (I also added the UIViewControllerBasedStatusBarAppearance key to the Info.Plist and tested with it set either to true or false):
import UIKit
    
class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        setNeedsStatusBarAppearanceUpdate()
    }
        
    override var prefersStatusBarHidden: Bool {
        return false
    }
}
  1. Second solution I tried was to use the deprecated method setStatusBarHidden in the App Delegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    application.setStatusBarHidden(false, with: .none)
    // Override point for customization after application launch.
    return true
}

In both cases status bar does not appear in landscape. Is there any way to see it ?


Solution

  • Your code is correct (this is all you need in a new vanilla iOS app project):

    override var prefersStatusBarHidden: Bool {
        return false
    }
    

    The problem is that this works only up through iOS 12. In iOS 13 and later, the runtime stopped interpreting a value of false to allow you to override the hiding of the status bar in landscape on an iPhone. Similarly, calling application.setStatusBarHidden fails to show the status in landscape.

    This is probably a side effect of the UIWindowScene architecture that was introduced in iOS 13. Or it might be intended to make all iPhone models behave the same way (with or without bezel).