Ralph Goodtimes
unread,Dec 10, 2009, 1:07:58 AM12/10/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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