2010-09-25 58 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

相關問題