Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

ryanbetts commented Sep 29, 2010

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

This comment has been minimized.

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
You can’t perform that action at this time.