If you'd like your app to be stuck in Landscape Orientation (Home button on the right), this tutorial is for you. After you have made the small changes below, when your application loads it will stay in landscape mode regardless of how you hold the phone.
1. open GlassAppDelegates.m
2. scroll down until you find:
- (void)applicationDidFinishLaunching: (UIApplication *)application {
3. add this as the first line in the above section:
application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;
4. Open GlassViewController.m
5. add this right before the last line, which is @end:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
if(interfaceOrientation == UIInterfaceOrientationPortrait)
return NO;
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight)
return YES;
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Comments (6)
ANDYED@... said
at 7:49 pm on Mar 3, 2009
See the commit trace at http://github.com/sintaxi/phonegap/commit/8d42fa05951d3ad743eb8250ec614015910bc01d
Kemal Seref said
at 11:59 pm on Apr 12, 2009
great! force portrait orientation by changing YES & No in 5.
jack bellis said
at 5:16 pm on Mar 1, 2010
Just what I needed, thanks. But I did have to interpret one thing and make one change. I'm a complete newbie to Xcode and Objective-C so I don't want to edit the wiki page, but hopefully this will help others. I got it to work via Phonegap 0.8.0 but
1) 'GlassAppDelegates.m' and GlassViewController.m look like they should just say AppDelegates.m and ViewController.m.
2) When I put the shouldAutorotateToInterfaceOrientation routine at the end I got a build error that it was redundant. I replaced the existing shouldAutorotateToInterfaceOrientation with the proposed code and it worked like a charm. (I wanted portrait so I reversed the Yes and No as in other comment.)
Perhaps the instructions are for an earlier version of Phonegap. Maybe I could have just edited the new shouldAutorotateToInterfaceOrientation routine but didn't look at it too hard since the code above worked.
Kevin Gaddy said
at 8:19 am on Jun 27, 2010
I did a search in my project from the method ("shouldAutorotateToInterfaceOrientation") in step 5 and found it in the "UIViewController.h. It says it's read only.
Am I doing something wrong or is this article outdated? I am using phonegap 0.9.1.
Thanks
matt c said
at 12:31 pm on Jun 27, 2010
In newer versions of Phonegap, you don't have to edit the code anymore--Look for 'appName-Info.plist' in the 'Resources' folder of your app. There is a property called 'Supported interface orientations' -- just delete the ones that you don't want supported in your app. Much easier!
Kevin Gaddy said
at 6:27 am on Jun 29, 2010
Thanks matt, that worked. I now have a new problem. In the iphone simulator I get the status bar in the correct orientation, but the webkit interface or page stays in portrait view. Is there another setting I need to edit in the 'appName-Info.plist' ? BTW, the ipad simulator works perfect, I just have problems with the iphone.
You don't have permission to comment on this page.