setStatusBarOrientation not working

2019-08-31 09:25发布

问题:

I'm trying to fix the orientation of status bar to Portrait, but not succeeded. I have tried:

[application setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO]; 

and also shouldAutorotateToInterfaceOrientation is set to return NO.

Please help me out.

回答1:

If you want to change the orientation when a particular view is showing, you should call [UIApplication setStatusBarOrientation:animated:] inside your [UIViewController viewWillAppear:] override method for each of the view controllers that force a particular orientation. That will cause a change when a view is being pushed onto the stack and when it's being popped off it. Make sure you call super in your override method.

Also change your shouldAutorotateToInterfaceOrientation method:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
   return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}