簡體   English   中英

移動UIToolbar的最佳方法是什么?

[英]What is the best way to move a UIToolbar?

這是一個有趣的問題。 在iPhone上,我有一個視圖設置,在屏幕底部有一個工具欄。 我目前正在嘗試使其成為通用應用程序,以便它也可以在iPad上運行。 我希望工具欄位於iPad屏幕的頂部,因此在特定viewController的viewDidLoad方法中,我具有以下代碼。

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]];
}

我遇到的問題是webView向下移動良好,但工具欄僅向上移動了大約iPhone屏幕的高度。 調用errorString告訴我,webView的原點位於0,44(應位於的位置),工具欄的原點位於0,0,但實際上它位於屏幕中間!

有人知道這是怎么回事嗎?

我說這是因為該框架被設置為iPhone框架的頂部(距底部320px),然后再調整視圖的大小以適合iPad屏幕。 但是,默認情況下,UIToolbar設置為固定在窗口底部(固定的底部邊距和靈活的頂部邊距),因此它與底部的距離為320px。

要解決此問題,請嘗試:

[self.aToolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin];

在設置工具欄的框架之前(如果在設置框架之前不起作用,請嘗試在其后放置)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM