Created
August 5, 2010 21:30
-
-
Save mwbrooks/510407 to your computer and use it in GitHub Desktop.
PhoneGap-iPhone UIWebView viewport fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* PhoneGap-iPhone UIWebView viewport fix */ | |
/** | |
Called when the webview finishes loading. This stops the activity view and closes the imageview | |
*/ | |
- (void)webViewDidFinishLoad:(UIWebView *)theWebView | |
{ | |
/* Fix the viewport to properly fit to the screen */ | |
CGRect windowFrame = [ [ UIScreen mainScreen ] bounds ]; | |
CGRect webViewFrame = [ [ UIScreen mainScreen ] applicationFrame ]; | |
webViewFrame.origin = windowFrame.origin; | |
webView.frame = webViewFrame; | |
return [ super webViewDidFinishLoad:theWebView ]; | |
} |
This works great until you put the iPad flat on a surface, then it gets confused when it is in landscape (only half the screen will show, thinks it is in portrait mode). Do you have an update to this to fix this issue?? Thanks in advance.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to get it to work on the iPad when launching an app in landscape orientation:
- (void)webViewDidFinishLoad:(UIWebView )theWebView
{
/ Fix the viewport to properly fit to the screen */
CGRect windowFrame = [ [ UIScreen mainScreen ] bounds ];
CGRect webViewFrame = [ [ UIScreen mainScreen ] applicationFrame ];
webViewFrame.origin = windowFrame.origin; //set the origin to 0,0
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight)
{
webViewFrame.size.width = windowFrame.size.height;
webViewFrame.size.height = windowFrame.size.width;
}
webView.frame = webViewFrame;
return [ super webViewDidFinishLoad:theWebView ];
}