UIWebView - Does not resize content on rotation change?
Solution 1
You have 2 options:
Add this into HEAD
section of your html file:
<meta name="viewport" content="width=device-width" />
Or call [myWebView reload]
when orientation changes
Solution 2
I had a similar problem. I solved it by executing javascript code to generate an event that updates the orientation of the page when the UIViewController
finished rotation:
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[webView stringByEvaluatingJavaScriptFromString:@"var e = document.createEvent('Events'); "
@"e.initEvent('orientationchange', true, false);"
@"document.dispatchEvent(e); "];
}
Solution 3
I tried the other suggestions above but they were not working the my static webpage I had loaded. I tried adding this line into the header of my webpage
<meta name="viewport" content="width=device-width" />
But it still didn't resize the page width after changing the orientation between landscape & portrait on my device. I then added this line to func viewDidLoad() and it worked perfectly. I'm running iOS 11.4
myWebView.autoresizingMask = UIViewAutoresizing.flexibleWidth
Solution 4
This question is old, but this should solve it:
myWebView.scalesPageToFit = YES;
Alternately, if you're using the Interface Builder, you can tick the check box under Attributes Inspector that says 'Sales page to fit.'
Hope it helps.
aryaxt
Updated on June 14, 2022Comments
-
aryaxt almost 2 years
So I have a
UIWebView
that displays static html content.When I start the
ViewController
in portrait and switch to landscape, it resizes the content correctly.But, when I start the page in landscape and switch to portrait, it doesn't resize my content, and scrolling is required in order to view all the content.
Is this a bug? Is there a solution to force resizing the content of a
UIWebView
?