動態

詳情 返回 返回

UIViewController中view在navBar和tabBar影響下佈局區域問題 - 動態 詳情

轉自: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模擬器上測驗過!

user avatar 323duqpq 頭像 jianqiu 頭像 savo_shen 頭像 shu_5b5b4cde7027a 頭像 alixitongruanjianjishu 頭像 tiandekaixinguo 頭像 michaellynx 頭像 slnongchang 頭像 CoolBreeze-SeclusionDream 頭像 gddg 頭像 mddblog 頭像 zouzaidadaomanshihuaxiang 頭像
點贊 12 用戶, 點贊了這篇動態!
點贊

Add a new 評論

Some HTML is okay.