轉自:https://www.cnblogs.com/bridge-wuxl/p/10790888.html
影響 View 佈局區域的有以下三個屬性: self.edgesForExtendedLayout (影響View佈局區域的主要屬性)
self.navigationController.navigationBar.translucent (navigationBar 是否半透明) self.tabBarController.tabBar.translucent (tabBar 是否半透明)
case 1: edgesForExtendedLayout = UIRectEdgeAll
條件: navigationBar.translucent = YES && tabBar.translucent = YES
結果: View Top == navigationBar Top,View Bottom == tabBar Bottom
條件: navigationBar.translucent = NO && tabBar.translucent = YES
結果: View Top == navigationBar Bottom,View Bottom == tabBar Bottom
條件: navigationBar.translucent = YES && tabBar.translucent = NO
結果: View Top == navigationBar Top,View Bottom == tabBar Top
條件: navigationBar.translucent = NO && tabBar.translucent = NO
結果: View Top == navigationBar Bottom,View Bottom == tabBar Top
case 2: edgesForExtendedLayout = UIRectEdgeTop
條件: navigationBar.translucent = YES && tabBar.translucent = YES
結果: View Top == navigationBar Top,View Bottom == tabBar Top
條件: navigationBar.translucent = NO && tabBar.translucent = YES
結果: View Top == navigationBar Bottom,View Bottom == tabBar Top
條件: navigationBar.translucent = YES && tabBar.translucent = NO
結果: View Top == navigationBar Top,View Bottom == tabBar Top
條件: navigationBar.translucent = NO && tabBar.translucent = NO
結果: View Top == navigationBar Bottom,View Bottom == tabBar Top
case 3: edgesForExtendedLayout = UIRectEdgeBottom
條件: navigationBar.translucent = YES && tabBar.translucent = YES
結果: View Top == navigationBar Bottom,View Bottom == tabBar Bottom
條件: navigationBar.translucent = NO && tabBar.translucent = YES
結果: View Top == navigationBar Bottom,View Bottom == tabBar Bottom
條件: navigationBar.translucent = YES && tabBar.translucent = NO
結果: View Top == navigationBar Bottom,View Bottom == tabBar Top
條件: navigationBar.translucent = NO && tabBar.translucent = NO
結果: View Top == navigationBar Bottom,View Bottom == tabBar Top
case 4: edgesForExtendedLayout = UIRectEdgeNone
條件: navigationBar.translucent = YES && tabBar.translucent = YES
結果: View Top == navigationBar Bottom,View Bottom == tabBar Top
條件: navigationBar.translucent = NO && tabBar.translucent = YES
結果: View Top == navigationBar Bottom,View Bottom == tabBar Top
條件: navigationBar.translucent = YES && tabBar.translucent = NO
結果: View Top == navigationBar Bottom,View Bottom == tabBar Top
條件: navigationBar.translucent = NO && tabBar.translucent = NO
結果: View Top == navigationBar Bottom,View Bottom == tabBar Top
iOS 7.0以後
self.navigationController.navigationBar.translucent 和 self.tabBarController.tabBar.translucent 默認值都為 YES.
iOS 6.0以下系統
navigationBar 和 tabBar 默認都是不透明的。edgesForExtendedLayout 的枚舉項:
UIRectEdgeNone = 0, navBar 底部與 tabBar 上部之間
UIRectEdgeTop = 1 << 0, navBar 上部與 tabBar 上部之間
UIRectEdgeLeft = 1 << 1,
UIRectEdgeBottom = 1 << 2, navBar 底部與 tabBar 底部之間
UIRectEdgeRight = 1 << 3,
UIRectEdgeAll = UIRectEdgeTop | UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight下面圖中展示了 UIView 的四種情況下的佈局區域,
綠色為目標 UIView:
View Top == navigationBar Bottom,View Bottom == tabBar Top
View Top == navigationBar Top,View Bottom == tabBar Bottom
View Top == navigationBar Bottom,View Bottom == tabBar Bottom
View Top == navigationBar Top,View Bottom == tabBar Top
注:我在iOS17.2模擬器上測驗過!