2012-07-03 35 views
3

我在iOS应用程序的UIPopoverController中显示UIWebView。UIPopover中的UIWebView - 报告大小

iPad报告它的窗口大小为980x1532。因此,当我加载一个外部页面时,它加载并渲染980像素宽。

我打这个webview的外部网站,所以我不能修改任何代码从服务器。

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

+0

为什么你需要一个UIWebView到大小报告?你是否试图强制popover达到这个尺寸? –

+0

正确。该网站具有响应js/css,并且如果它在320x480窗口中呈现,对我的用户来说会更好。 –

+0

然后,您应该只需要在创建时设置弹出窗口大小,而不是依靠Web视图来完成此操作。 –

回答

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; 

}

+0

谢谢 - 作品! –

+0

太棒了!我想知道你是怎么想出这个解决方案的。 –

+1

很多很多很多的谷歌搜索和尝试的东西:D我希望这个答案被接受:) –