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.
How to rotate the screen on your iPad. Make sure that Rotation Lock is off: Swipe down from the top-right corner of your screen to open Control Center. Then tap the Rotation Lock button to make sure it's off. Turn your iPad sideways.
iOS Settings and (lack of) Apps To find the setting in iOS 11, you will need to swipe up from the bottom of the screen and open the Control Center. Locate the Rotation Lock icon that looks like a lock, with an arrow circling it in a clockwise direction.
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:
iPad Simulator WebView/Google Maps API Issue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With