UIPopover中的UIWebView - 报告大小

时间:2012-07-03 19:47:19

标签: ios uiwebview uipopovercontroller

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

iPad正在报告其窗口大小为980x1532。因此,当我加载外部页面时,它会加载并渲染980px宽。

我正在访问此网页浏览中的外部网站,因此我无法修改服务器中的任何代码。

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

1 个答案:

答案 0 :(得分:14)

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

结帐此问题的第二个答案displaying Wiki mobile page in UIWebView within UIPopoverController

它解决了我的问题代码在

之下
- (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;

}

相关问题