0x00 safeAreaInsets
在 2 个方法内 viewDidLoad
、viewDidLayoutSubviews
测试 safeAreaInsets
的具体值
viewDidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"1.UIEdgeInsets = %@", NSStringFromUIEdgeInsets(self.view.safeAreaInsets));
}
输出日志:
5s: 1.UIEdgeInsets = {0, 0, 0, 0}
6p: 1.UIEdgeInsets = {0, 0, 0, 0}
X: 1.UIEdgeInsets = {0, 0, 0, 0}
XR: 1.UIEdgeInsets = {0, 0, 0, 0}
viewDidLayoutSubviews:
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
NSLog(@"2.UIEdgeInsets = %@", NSStringFromUIEdgeInsets(self.view.safeAreaInsets));
}
输出日志:
a.导航栏透明,无
tabbar 的情况下
5s: 2.UIEdgeInsets = {64, 0, 0, 0}
6p: 2.UIEdgeInsets = {64, 0, 0, 0}
X: 2.UIEdgeInsets = {88, 0, 34, 0}
XR: 2.UIEdgeInsets = {92, 0, 34, 0}
b.导航栏不
透明,无
tabbar 的情况下
XR:
self.view.frame = {{0, 92}, {414, 804}}
2.UIEdgeInsets = {0, 0, 34, 0}
c.导航栏不
透明,有
tabbar 的情况下
6P:
self.view.frame = {{0, 64}, {414, 672}}
2.UIEdgeInsets = {0, 0, 49, 0}
X:
self.view.frame = {{0, 88}, {375, 724}}
2.UIEdgeInsets = {0, 0, 83, 0}
XR:
self.view.frame = {{0, 92}, {414, 804}}
2.UIEdgeInsets = {0, 0, 83, 0}
总结一下:
在 viewDidLayoutSubviews
方法内,才能获取到 具体值
根据 self.view.frame
的 y
值,可以判断顶部导航栏 是否透明
根据 UIEdgeInsets
的 bottom
值,可以判断底部标签栏 是否透明
0x01 我的小作品
欢迎体验我的作品之一:小笔记-XNote
笔记一步到位!
App Store
搜索即可~