UIWebView框架在加载横向和纵向时填充屏幕

时间:2011-03-17 00:28:59

标签: iphone ios uiwebview

我在我的视图中添加了一个UIWebView,当我在肖像时它工作正常。但是,当我在横向加载相同的UIWebView时,它不会填满屏幕。我怀疑它来自我如何设置框架:

CGRect screen = [[UIScreen mainScreen] bounds];
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, screen.size.width, screen.size.height)];
webView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
webView.scalesPageToFit = YES;

是否有更好的方法可以在横向和纵向中正确加载,并在旋转时填充屏幕?

2 个答案:

答案 0 :(得分:0)

您对父视图调整大小的确定程度如何? UIWebView子视图不会比它的父级大...

答案 1 :(得分:0)

我有同样的问题..在我记录了self.view.frame.size.width后,我很惊讶地发现它是320而不是480.解决方法是:

- (void)viewWillAppear:(BOOL)animated {
[self.view setBounds:CGRectMake(0.f, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.view setCenter:CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2)];
[(UIWebView*)myWebView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];}

似乎在显示视图之前返回了正确的self.frame大小:)