1
votes

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

1
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
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
the view controller calling the [self.navigationController pushViewController:portraitDetailsViewContoller animated:YES]; line of code is in landscape orientation.Matt
check out the following stackoverflow.com/questions/181780/…Allen
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

1 Answers

1
votes

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);
}