2010-09-25 55 views
0

我添加了一个导航栏,一个webview和一个工具栏(从上到下)作为viewcontroller视图的子视图。我希望导航栏和工具栏的高度在横向缩小一点,所以我使用autoresizingmask来使高度更灵活。 (UIViewAutoresizingFlexibleHeight将导航栏和工具栏的高度从44缩小到大约30):如何在iPhone中以横向模式正确调整webview的大小?

webNavBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin; 
webToolBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin; 
webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 

现在我发现,当我旋转设备为横向模式,将有上的顶部和底部的两个空白白条webview(每个空白栏的高度是44-30)。导航栏和工具栏似乎处于正确的位置。有什么方法可以调整webview并填补空白?

回答

0

您确定Web界面的Autoresizing页边距设置正确吗?总是可以这样做:

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    webView.frame = self.view.frame; 
} 

不知道,如果这将工作,但值得一试。

+0

谢谢您的回答,但Webview是不是全屏视图。无论如何,你给我一个想法,我可能会重置其框架以获得正确的尺寸。 – 2010-10-18 14:38:36

+1

如果你在超级课堂上做任何事情,请确保你也调用super方法。 – Rich 2014-04-28 10:15:04

0

选中此链接。 UIWebView not re-sizing after changing orientation to landscape

这为我工作: - 下面的代码添加到具有web视图控制器: -

(void)willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    [self.myWebView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
} 
+0

如果你在超类中做任何事情,请确保你也通过'super'方法调用。 – Rich 2014-04-28 10:15:44

相关问题