Making the iPhone simulator behave in landscape for the 1st view

Posted by Kieran on November 5, 2009 under Mobile, iPhone | Be the First to Comment

Discovered some fairly interesting behaviour of the iPhone simulator that had me stumped for a little while

When you want to have an application that starts up in Landscape without a status bar
the following code snippit placed into your applicationDidFinishLaunching method of the app delegate will allow you to test in the emulator!

//For your normal application execution on the iPhone, this can also be done in the info.plist
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];

//How to make the simulator behave itself preprocess for just the simulator
#if (TARGET_IPHONE_SIMULATOR)
UIScreen *screen = [UIScreen mainScreen];
tabBarController.view.bounds = CGRectMake(0, 0, screen.bounds.size.height, screen.bounds.size.width);
tabBarController.view.transform = CGAffineTransformConcat(tabBarController.view.transform, CGAffineTransformMakeRotation((M_PI * 90 / 180.0)));
tabBarController.view.center = window.center;
#endif

tabBarController in this case is the first view controller given to the window

Hope this helps someone else!

Add A Comment