1

I have a simple navigation app that has 95% of all views displayed in landscape mode. With the one view that makes sense to only show in Portrait mode i have inserted the following code in:

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

The problem is that when the app navigates to the view (from a landscape orientated view) it does not switch the orientation to portrait, only when the device is rotated will it snap into portrait and stay in portrait. Is it possible to force it to load in portrait mode on load of the view?

Thanks in advane

Matt
  • 3,305
  • 11
  • 54
  • 98
  • can you show the viewcontroller hierarchy? the above rotation code only works in your top viewcontroller, not the viewcontrollers you pushed into navigation controller. – Allen Feb 01 '12 at 22:10
  • In this situation the top most item would be the navigationcontroller which supports all orientations i would think. I than push the new portrait controller into the navigation controller via: [self.navigationController pushViewController:portraitDetailsViewContoller animated:YES]; – Matt Feb 01 '12 at 22:20
  • the view controller calling the [self.navigationController pushViewController:portraitDetailsViewContoller animated:YES]; line of code is in landscape orientation. – Matt Feb 01 '12 at 22:21
  • check out the following http://stackoverflow.com/questions/181780/is-there-a-documented-way-to-set-the-iphone-orientation – Allen Feb 01 '12 at 23:03
  • Isn't this a big no-no with apple? I mean you are trying to force a view in portrait mode while the device itself is in landscape mode? Apple gate keepers have a very trigger happy reject finger. Just saying. – Sam B Mar 12 '12 at 16:59
  • No, that is not a no-no for Apple. Check out youtube app in iOS 5 how it makes transition to video... – Borut Tomazin Oct 15 '12 at 07:34

1 Answers1

1

I think you should go through : shouldAutoRotateToInterfaceOrientation method of UIViewController Class.

This function returns YES if the orientations is supported by your UIView. If you return YES only to the portrait orientation, then the iPhone will automatically be put in that orientation.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Bhavin
  • 27,155
  • 11
  • 55
  • 94