Manually set interface orientation

brad_roush picture brad_roush · Aug 31, 2011 · Viewed 7.4k times · Source

Is there any easy way to manually set the orientation of an interface? I need to set the interface to portrait even though the device orientation might be in landscape during loading. Kinda want to stay away from CGAffineTransforms.

Answer

Shane Powell picture Shane Powell · Sep 1, 2011

One method I know that works for me (and is a bit of a hack and can display one orientation before changing to the orientation you want) is:

- (void)viewDidAppear:(BOOL)animated 
{
    [super viewDidAppear:animated];

    UIApplication* application = [UIApplication sharedApplication];

    if (application.statusBarOrientation != UIInterfaceOrientationPortrait)
    {
        UIViewController *c = [[UIViewController alloc]init];
        [self presentModalViewController:c animated:NO];
        [self dismissModalViewControllerAnimated:NO];
        [c release];
    }
}