UIWebView不自动调整大小以适合屏幕

问题描述:

我有一个应用程序使用UIViewController在UIWebView中显示文章,其中一些文件有图像。我有它设置,这样,当被点击图像调用UIWebView不自动调整大小以适合屏幕

- (void)displayImage:(NSInteger)i { 
ImageViewController * imageVC = [[ImageViewController alloc] initWithImageId:i]; 
[self.navigationController pushViewController:imageVC animated:YES]; 
[imageVC release]; 

}

此加载另一个UIViewController中。 我所有的观点都很好地回应了旋转。 ImageViewController保持图像的比例,我的ArticleViewController用文本填充屏幕。但是,只要我在查看ImageViewController的同时将屏幕旋转到横向模式并按下后退按钮。之前的UIViewController不正确地进行自动修改,增加了文本的字体大小,而不是将更多的单词放在一行上。

编辑:

这是一篇文章视图控制器:

This is an article view controller

这是出现在当您单击图像ImageViewController:

ImageViewCOntroller - portrait

现在,如果我们在这里改变方向...

ImageViewCOntroller - landscape

并点击后退按钮,文章内容被不适当地调整大小以适应窗口。

ArticleViewCOntroller - landscape bad

这可以通过关闭iPhone的两倍予以纠正。这是这篇文章在景观中的样子。

ArticleViewCOntroller - landscape good

问题有事情做与UIWebView中不恰当地自动调整大小时它是当前不可见。我能做些什么来解决这个问题?

+0

您是否找到了解决方案? – 2013-05-18 12:50:51

您需要在Interface Builder中这样做

点击你的UIWebView并按下Apple-3来调出“Size Inspector”。

在“自动调整”下,确保选中里面的两个箭头。这将确保视图大小始终最大化到其容器。 例如:

+1

我已经完成了这项工作,除了我在原始问题中解释的情况外,它工作良好。有更多的建议吗? – Tozar 2010-11-12 18:11:38

您可以通过相加依赖于设备的方向不同的CSS样式改变它在服务器端

/* Landscape */ 
@media screen and (min-width: 321px) 
{ 
    body{ 
    width: 320px; 
    }  
} 
/* Landscape */ 
@media screen and (min-width: 321px) 
{ 
    body{ 
    width: 480px; 
    }  
} 

,或者你可以从客户端视改变: 如果你的页面已经得到了视元标签:

<meta name="viewport" id="view" content="width=320px, minimum-scale=1.0, maximum-scale=1.0"> 

然后在你的代码,你可以改变这种视每次方向变化:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
if(interfaceOrientation == UIDeviceOrientationLandscapeLeft)  
[uiwebview stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementById(\"view\").setAttribute('content', 'width=480');"]]; 
} 
.... 

并在方向为纵向时再次更改它

+0

解决方案的视口部分像魅力一样工作。谢谢! – 2011-10-27 13:00:12

供将来参考。你可以用这个程序来做到这一点。

[webView setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth)];