How to get the iPhone to open in Landscape mode on 0.8.0

23 views
Skip to first unread message

joeda...@me.com

unread,
Nov 28, 2009, 11:09:05 AM11/28/09
to phonegap
Hello,

I am new to using Phonegap and am having a bit of trouble getting my
iPhone app to run in landscape mode on Phonegap 0.8.0.

In the PhoneGap.plist, I set the StartOrientation to "landscapeRight"
and I also set the RotateOrientation to "landscape".

When I compile the app and load it in the simulator or the device, the
status bar rotates the way it should, but the WebView is still in
portrait mode. I have to rotate the device around a couple of times
before the WebView snaps into the proper landscape mode.

I have tried every conceivable combination I can think of and it just
seems to not work.

Is there something I am missing to make this work?

Any help would be greatly appreciated.

Best,
Joe Dakroub

Ralph Goodtimes

unread,
Dec 10, 2009, 1:07:58 AM12/10/09
to phonegap

Phew! This one took me good 72 hours to figure out.

Joe, you may have found a solution to this, but just in case others
are struggling with this one, I'll share what worked for me:

Disclaimer: Use this hack at your own risk.

Purpose: To force landscape mode from start, and to fix the webView's
annoying tendency to think it's still in portrait mode, even when it's
not!

This works with PhoneGap version 0.8.0, and was tested with both
iPhone Simulator 3.1.2 and a device with iPhone OS 3.1.2:

FIRST PART:

- Open PhoneGap.plist and set these values:
- AutoRotate: unchecked.
- StartOrientation: landscapeRight
- RotateOrientation: landscape

Save the file.


SECOND PART:

Now, in XCode, go to the Classes group, and find and open the
PhoneGapViewController.m file. Then, do the following:
- Locate the shouldAutorotateToInterfaceOrientation: method. It's
actually the first function in the file, and it looks like this:

- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation) interfaceOrientation
{
if (autoRotate == YES) {
return YES;
} else {
if ([rotateOrientation isEqualToString:@"portrait"]) {
return (interfaceOrientation ==
UIInterfaceOrientationPortrait ||
interfaceOrientation ==
UIInterfaceOrientationPortraitUpsideDown);
} else if ([rotateOrientation isEqualToString:@"landscape"]) {
return (interfaceOrientation ==
UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation ==
UIInterfaceOrientationLandscapeRight);
} else if ([rotateOrientation
isEqualToString:@"landscapefix"]) {
return YES;
} else {
return NO;
}
}
}

As a first line, right before the if () sentence, add this:
return YES;

Yup, a simple return. You may very well replace the whole contents
with that line. I opted for leaving things there in case I needed to
undo my changes. So, your function should either look like this:

- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation) interfaceOrientation
{
return YES;
if (autoRotate == YES) {
return YES;
} else {
if ([rotateOrientation isEqualToString:@"portrait"]) {
return (interfaceOrientation ==
UIInterfaceOrientationPortrait ||
interfaceOrientation ==
UIInterfaceOrientationPortraitUpsideDown);
} else if ([rotateOrientation isEqualToString:@"landscape"]) {
return (interfaceOrientation ==
UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation ==
UIInterfaceOrientationLandscapeRight);
} else if ([rotateOrientation
isEqualToString:@"landscapefix"]) {
return YES;
} else {
return NO;
}
}
}

Or this:

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


It's not that elegant, but hey, works for me. ;-)

I hope this bug might is fixed in future versions, so this hack is
unnecessary. Having said that, I LOVE PhoneGap... good job putting
this project together, PG team!

- RGt


Ralph Goodtimes

unread,
Dec 10, 2009, 1:15:07 AM12/10/09
to phonegap
In my previous post, I suggested to add a simple "return YES;" as a
first line to the shouldAutorotateToInterfaceOrientation: method in
the PhoneGapViewController.m file. This solution is more elegant
(taken from the phonegap documentation site:
http://phonegap.pbworks.com/Forcing-a-Landscape-Orientation ):

- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation) interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationPortrait)
return NO;
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight)
return YES;
return (interfaceOrientation == UIInterfaceOrientationPortrait);
Reply all
Reply to author
Forward
0 new messages