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

注:

本文是受 http://blog.sina.com.cn/s/blog_1410870560102wu9a.html 启发而写的一篇文章。

本文论证结果是在xcode iOS 12.1 IPhone XR 模拟器上进行的数据校对。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值