簡體   English   中英

將標簽欄快速移動到屏幕頂部

[英]Moving Tab Bar to the top of the screen swift

我想在屏幕頂部有標簽欄。 一篇文章建議執行以下操作(我將以下代碼放在 UITabBarController 的 viewDidLoad() 中):

代碼

let tabBar = self.tabBar

// yStatusBar indicates the height of the status bar
let yStatusBar = UIApplication.sharedApplication().statusBarFrame.size.height

// Set the size and the position in the screen of the tab bar
tabBar.frame = CGRectMake(0, yStatusBar, tabBar.frame.size.width, tabBar.frame.size.height)

這個解決方案有兩個問題:

  1. 屏幕底部留下了一個黑色區域,其中標簽欄是

  2. Tab 欄覆蓋屏幕頂部的視圖 - 該視圖的約束是相對於設備的,但它們應該是相對於 Tab 欄的。 但是,當在 IB 中設計屏幕時,沒有與之相關的標簽欄。

有沒有辦法克服這些問題? PS我是IOS新手

雖然它違反了人機界面指南但是如果你真的想要存在黑客攻擊。

您可以在故事板中創建一個空白的UIView(設置了適當的約束),它基本上是加載時tabBar的占位符。

然后,為相對於已設置的此視圖設置其他視圖的頂部約束。

這有效,但可能不是最好的做法

let tabBar = self.tabBarController?.tabBar
// Set the size and the position in the screen of the tab bar
tabBar?.frame = CGRect(x: 0, y: self.view.frame.height, width: (tabBar?.frame.size.width)!, height:  (tabBar?.frame.size.height)!)
}

暫無
暫無

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

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