Altinio
Altinio

Reputation: 21

Swift 2 prefersStatusBarHidden() Not Called

I'm in the same situation as this problem. For some reason, the status bar still doesn't fade in or out. I've pretty much tried every solution posted on this website.

I'm using a UINavigationController -> UIViewController.

I have View controller-based status bar appearance set to YES. Here's my code:

var statusBarHidden = false

func toggleStatusBarHidden() {
    statusBarHidden = !statusBarHidden
    setNeedsStatusBarAppearanceUpdate()
}

override func prefersStatusBarHidden() {
    return statusBarHidden
}

override func preferredStatusBarUpdateAnimation() {
    return .Fade
}

Any ideas why that might be the case?

Upvotes: 0

Views: 889

Answers (2)

Altinio
Altinio

Reputation: 21

Figured out my problem. I created the function on a view controller bounded by a UIContainerView. I need to move those methods into the parent view controller.

Upvotes: 1

Faiz Mokhtar
Faiz Mokhtar

Reputation: 948

Had the same problem as well. I ended up using the following method in viewWillAppear or viewWillDissapear:

 UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: .None)

Note: It's deprecated in iOS 9.0, but still usable.

Upvotes: 0

Related Questions