6

I've used this code to force an orientation change back to portrait when the user is finished watching the video (it allows viewing in landscape mode), before popping the video view controller off the navigation controller:

//set statusbar to the desired rotation position
[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationPortrait animated:NO];

//present/dismiss viewcontroller in order to activate rotating.
UIViewController *mVC = [[[UIViewController alloc] init] autorelease];
[self presentModalViewController:mVC animated:NO];
[self dismissModalViewControllerAnimated:NO];

[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];

This worked perfectly until iOS 5.1.1. I've even tried to use the new present/dismiss methods after reading in another post that those should be used now:

[self presentViewController:mVC animated:NO completion:NULL];
[self dismissViewControllerAnimated:NO completion:NULL];

The problem is it doesn't work at all. After I rotated the video viewer to landscape and then pop it, my settings view (table view controller) comes back, but also in landscape mode.

I've even tried the tip from Here

"The setStatusBarOrientation:animated: method is not deprecated outright. However it now works only if the supportedInterfaceOrientations method of the topmost full screen view controller returns 0. This puts the responsibility of ensuring that the status bar orientation is consistent into the hands of the caller."

So I've experimented with setting a flag to force supportedInterfaceOrientations to return 0 (before calling the first code block above) but it doesn't work either.

Does anybody have a solution for this? Thanks for your time and effort.

1
  • 1
    Exactly the same issue but like you, I didn't find a solution. Anybody?
    – nicolas
    Sep 25, 2012 at 14:44

3 Answers 3

17

setStatusBarOrientation method has changed behaviour a bit. According to Apple documentation:

The setStatusBarOrientation:animated: method is not deprecated outright. It now works only if the supportedInterfaceOrientations method of the top-most full-screen view controller returns 0

3
  • Been looking for this answer for a long time, just stumbled upon this, thanks!
    – Pete.Mertz
    Sep 26, 2012 at 23:41
  • 3
    That's strange because the docs also say "The value returned by this method must not be 0"
    – Sulthan
    May 18, 2013 at 19:26
  • This idea won't work if you actually do want to allow more than one orientation.
    – AWrightIV
    Sep 29, 2013 at 18:52
2

Your root view controller should answer false to the method shouldAutorotate in order that your app responds to setStatusBarOrientation:animated

From Apple Documentation: "if your application has rotatable window content, however, you should not arbitrarily set status-bar orientation using this method"

To understand that, put a breakpoint in the shouldAutorotate method and you will see that it is called juste after setting the status bar orientation.

0

Here is how I fixed.

https://stackoverflow.com/a/14530123/1901733

The current question is linked with the question from the url above.

The statusBarOrientation is a real problem in ios6.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.