views:

536

answers:

1

On the iPad, I present a view in the "detail" side of a split view controller that is basically just a UIWebView, which loads an HTML file in the application bundle. The application supports rotation and hides/shows the "master" side of the split as appropriate.

When the UIWebView is initially loaded in landscape mode, its content seems to be "sized" properly... the content is taller than the screen, so you can scroll vertically, but not horizontally. (The HTML content is nearly all text styled with CSS, with only a small ~300x50 image at the bottom.)

If you then rotate the screen to portrait, the HTML content still seems to be sized okay -- vertical scrollbar is present, but not horizontal, as it was initially. Rotating back to landscape and everything is still peachy.

So far, so good.

Now, if the UIWebView initially loads in portrait orientation, everything is also "sized" properly (vertical scrollbar, no horizontal). But, if you rotate it to landscape, the content suddenly gets a horizontal scrollbar, because one of the paragraphs of text is wider than the width of the UIWebView. (Not coincidentally, I'm sure, but that long paragraph is sized perfectly for the slightly larger width the UIWebView has when it's oriented as portrait.)

I was expecting/assuming that rotation of the iPad would cause the UIWebView to have its frame be resized, and when it's resized, to also resize its HTML content appropriately. (Think of taking a Web browser window and shrinking it.) Why isn't that happening for me?

I would like to avoid using the "Scales Pages to Fit" property because the text shrinks non-deterministically.

+3  A: 

Just solved my issue with this by adding this HTML5 Viewport meta tag:

<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />

to the head section of my HTML, maybe a variation of this meta tag may help?

Although my issue was triggered when my app was started in landscape mode, while yours in portrait mode, it may be a common cause.

I also had another funny issue with the webView in iPad and the common solution seems to be that meta tag:

http://stackoverflow.com/questions/2790482/ipad-simulator-webview-google-maps-api-issue

EagleOfToledo
Interesting. Since this HTML might be used in other browsers/platforms later, I wasn't sure about adding this tag at first. But if I simplify it to just `content="initial-scale=1.0"`, it should be rather benign. Thanks!
Shaggy Frog