2010-04-16 46 views
2

這是一個有趣的問題。在iPhone上,我有一個在屏幕底部有一個工具欄的視圖。我目前正在嘗試將其設置爲通用應用程序,以便在iPad上運行。我希望工具欄位於iPad屏幕的頂部,因此在特定viewController的viewDidLoad方法中,我有以下代碼。移動UIToolbar的最佳方式是什麼?

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
    //move the toolbar to the top of the page and move the webview down by the height of the toolbar 
    CGRect toolBarFrame = self.aToolBar.frame; 
    CGRect webFrame = self.aWebView.frame; 

    webFrame.origin.y = toolBarFrame.size.height;  
    [self.aWebView setFrame:webFrame];  

    toolBarFrame.origin.y = 0; 
    [self.aToolBar setFrame:toolBarFrame]; 

    [Utils errorString:[NSString stringWithFormat:@"origen: x=%f y=%f", self.aToolBar.frame.origin.x, self.aToolBar.frame.origin.y]]; 
    [Utils errorString:[NSString stringWithFormat:@"origen: x=%f y=%f", self.aWebView.frame.origin.x, self.aWebView.frame.origin.y]]; 
} 

我遇到的問題是,web視圖向下移動很好,但只工具欄上移至什麼似乎是iPhone屏幕的高度。對errorString的調用告訴我,webView的原點是0,44(它應該是),並且工具欄的原點是0,0,但它實際上是在屏幕中間的某個位置!

任何人都知道這裏發生了什麼?

+0

你能後所有的viewDidLoad中(如果它不設置框架,嘗試後把它工作之前)之前

[self.aToolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin]; 

爲了解決這個問題的嘗試? – MathieuF 2010-10-06 21:57:39

回答

0

我想說這是因爲框架被設置爲iPhone框架的頂部(因此底部爲320px),然後視圖被調整大小以適應iPad屏幕。不過,默認情況下,UIToolbar被設置爲粘貼到窗口的底部(固定底部邊距和靈活的頂部邊距),因此它的底部保持320px。設置工具欄的框架

相關問題