WebView not working correctly on orientation change

橙三吉。 提交于 2019-12-13 08:13:56

问题


I have a Universal app with a webView which resize when an orientation change occurs. On the iPad simulator, the webView automatically reflows to fit the new width. But on the iPhone simulator, the content doesn't reflow and some of it gets cut off.

Is this a known WebView Bug ? How do I fix this issue?

My webview just loads a remote html page.

I am testing on IOS 4.3


回答1:


In the interface builder, you have to adjust the properties of the WebView to make it stretch on orientation change. Make sure you did that. It looks like this in Xcode:




回答2:


IT is very simple you implement this code

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
 {

    CGRect frame = webview.frame;//UIWebView* webview;
    frame = self.view.frame;
    webview.frame=frame;
    NSString *embeded_url = [NSString stringWithFormat:@"<html> <head> <meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 000\"/></head><body style=\"margin-top:0px;margin-left:0px\"><div><object width=\"%f\" height=\"%f\"><param name=\"movie\" value=\"%@\"></param></object></div></body></html>",frame.size.width,frame.size.height ,video_url];//url for video
    [ webview loadHTMLString:embeded_url baseURL:nil];//reload the web view from cache 

}

didRotateFromInterfaceOrientation: method is called at the time of orientation change occurred and resize your web view. My webview just loads a remote html page and it works fine in 4.X & 5.X



来源:https://stackoverflow.com/questions/8549960/webview-not-working-correctly-on-orientation-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!