Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mwbrooks
Created August 5, 2010 21:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwbrooks/510407 to your computer and use it in GitHub Desktop.
Save mwbrooks/510407 to your computer and use it in GitHub Desktop.
PhoneGap-iPhone UIWebView viewport fix
/* 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 ];
}
@ryanbetts
Copy link

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 ];
}

@ceze33
Copy link

ceze33 commented Dec 10, 2010

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