UIPopover中的UIWebView - 报告大小

Liy*_*ang 3 uiwebview uipopovercontroller ios

我在iOS应用程序的UIPopoverController中显示UIWebView.

iPad报告其窗口大小为980x1532.因此,当我加载外部页面时,它会加载并呈现980px宽.

我在这个webview中访问了一个外部网站,因此我无法修改服务器中的任何代码.

有没有办法设置它,以便iPad UIWebView将报告弹出窗口的大小(320x480)?

adr*_*ian 14

问题可能出在HTML中.该页面设置了content ="width = device-width",它将uiWebView内容大小设置为设备大小与视图大小.

结帐这个问题的第二个答案,在UIPopoverController中的UIWebView中显示Wiki移动页面

它解决了我的问题代码如下

- (void)webViewDidFinishLoad:(UIWebView *)aWebView {
if(aWebView.frame.size.width < aWebView.window.frame.size.width) {
    // width=device-width results in a wrong viewport dimension for webpages displayed in a popover
    NSString *jsCmd = @"var viewport = document.querySelector('meta[name=viewport]');";
    jsCmd = [jsCmd stringByAppendingFormat:@"viewport.setAttribute('content', 'width=%i, initial-scale=1.0, user-scalable=1');", (NSUInteger)aWebView.frame.size.width];
    [aWebView stringByEvaluatingJavaScriptFromString:jsCmd];
}
// stop network indicator
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
Run Code Online (Sandbox Code Playgroud)

}