问题
I want to show the status bar on portrait mode only, when I rotate the screen the status bar hides as intended but if I push / show a new View Controller the status bar appears again.
I've tried the following without success:
- Setting
View controller-based status bar appearance
toNO
in theinfo.plist
file - Using
setNeedsStatusBarAppearanceUpdate()
onself
and onNavigationController
- Setting
prefersStatusBarHidden: Bool
totrue
- Also tried
UIApplication.shared.setStatusBarHidden(true, with: UIStatusBarAnimation.none)
- Also extending NavigationController. seen here
Any help will be appreciated. Thanks.
回答1:
Try Following Code
override var prefersStatusBarHidden: Bool {
if UIDevice.current.orientation.isPortrait{
return false
}
return true
}
来源:https://stackoverflow.com/questions/42788577/swift-3-unable-to-hide-status-bar-on-a-viewcontroller