1

I have two ViewController one support orientation another not, but when I rotate in second ViewController (the one which supports orientation) to landscape and back to first ViewController(doesn't support orientation) at the meantime second view still remain landscape it will change the first view become landscape as well but it not supposed to be landscape while first ViewController is not support orientation, how do I prevent this ?

The thing I want is the first view will always be portrait no matter how you rotate the phone especially when back from second view and it was in landscape.

2 Answers 2

0

in viewWillAppear:Animated of your first controller, call

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];

And of course, set up the shouldAutoRotateToInterfaceOrientation to return YES only on UIInterfaceOrientationPortrait.

4
  • this only rotate the device back to potrail but my view was still in landscape,others way?
    – issac
    Apr 10, 2009 at 1:56
  • You need to make sure the correct view controller is receiving the rotate events. Some times adding a view controller will cause that to receive events even after removing it; Also, I know with at least TabBarViewControllers, it doesn't send rotate events to its children, so you have to override.
    – Ed Marty
    Apr 10, 2009 at 13:21
  • I think Ed was meant [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait]; above source is only change orientation of status bar not the views.
    – Yoon Lee
    Apr 20, 2011 at 9:41
  • Changing the status bar orientation changes the view's orientation.
    – Ed Marty
    Apr 21, 2011 at 12:25
-1

in viewWillAppear:Animated of your first controller, call [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];

Your Answer

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

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