简体   繁体   中英

Webview content not resizing

I have a webview.. with the following attributes:

1.scalesPageToFit

2.Autoresizing masks

3.contentmode = aspectFit

After loading it fits to the page as obvious. But as soon as i zoom in and then zoom out to normal; rotating the device doesn't fit completely.

As a tweak, i have checked if the orientation mode is landscape reload the web page. I read various posts in this regard, but couldn't find any solution.

You have 2 folowing options:

Add this into head section of your html file:

 <meta name="viewport" content="width=device-width" />

Or call [myWebView reload] when orientation changes

You can use this Code

NSString *website =@"http://www.google.com";
NSURL *url = [NSURL URLWithString:website];
NSURLRequest *requestURL =[NSURLRequest requestWithURL:url];

mywebview.scalesPageToFit = YES;
mywebview.autoresizesSubviews = YES;    

[mywebview loadRequest:requestURL];

It took more than 2 days to find out the reason causing this issue. Actually webview was working correctly except the fact that if you try to use PinchGesture to zoom out further.. webview will baheve in the same way.

To overcome this issue, we need to set the zoom scale of scroll view in Webview under willRotate method. However, it's animating weirdly but one can make a guess where the issue lies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM