我的應用程序有一個tabBarController作爲主控制器,我需要從任何視圖控制器獲取tabBar的高度,以計算其餘元素的正確位置。如何以編程方式獲得它?謝謝。xcode get UITabBar height
4
A
回答
12
我強烈建議設置您的視圖層次結構,使得外部視圖通過容器視圖進行自動調整,然後更具體的內部視圖可以檢查外部佈局視圖的邊界並在適當的時候適當放置。
但是,如果你的要求使得該是不可能的(或極其複雜的,你真的需要指定點應有盡有),你可以得到標籤欄的高度與UIViewController
的tabBarController
屬性:
// from inside the view controller
CGSize tabBarSize = [[[self tabBarController] tabBar] bounds].size;
1
對於斯威夫特使用本:
let tabBarHeight = tabBarController?.tabBar.bounds.size.height ?? 0
它返回的TabBar的高度時tabBarController不爲零,否則爲0
相關問題
- 1. UITabbar在Xcode 6
- 2. 要自定義UITabBar的顏色在Xcode
- 3. Xcode:在UITabBar上添加過渡動畫
- 4. JS「Window」width-height vs「screen」width-height?
- 5. HTTP GET方法在Xcode
- 6. get image WIDTH和HEIGHT併爲任何圖像寫屬性
- 7. uitabbar到uitableview
- 8. Monotouch:UITableViewCell height
- 9. height = 2px和height = 2有什麼區別
- 10. HTML/CSS Div(height:80px)over Div(height:100%;)
- 11. UITabbar + ModalViewController
- 12. UITabBar - iPhone
- 13. iPhone + UITabBar
- 14. UITabBar padding
- 15. UITabBar Fuctionality
- 16. 當添加標籤欄項目(UITabBar)時,XCode 4.3崩潰
- 17. 以編程方式在Xcode中按下UITabBar按鈕
- 18. getHeight()vs getLayoutParams()。height
- 19. WPF UserControl TreeView Height
- 20. Win32 DrawText line height
- 21. iFrame和「max-height」
- 22. React-native flex height
- 23. Autogrow textarea height 0px?
- 24. Bootstrap main 100 height
- 25. LWJGL Display.setWidth/Height?
- 26. $(document).height()no workey
- 27. css min-height ie8
- 28. three.js shape holes height
- 29. frameset column height
- 30. listview row height
我認爲知道tabBar高度的一種情況是很有幫助的,即使視圖按照您的建議進行了自動調整,也必須調整視圖以考慮鍵盤的外觀。在這種情況下,鍵盤將覆蓋tabBar以及部分受影響的視圖,因此視圖必須根據鍵盤高度和TabBar高度之間的差異進行自我調整。我想到的情況是tabBar是rootViewController,活動視圖是其後代。 – 2013-03-30 20:21:12
我有這個完全相同的用例。當鍵盤顯示時使用tabBar時,是否有更好的方法來調整元素的插入/高度/原點? – 2013-10-13 00:47:17