美文网首页
ios11和iphoneX的适配笔记

ios11和iphoneX的适配笔记

作者: 快乐的tomato | 来源:发表于2018-05-22 18:00 被阅读22次

一、和其他机型的差异

1、statusBar的高度

其他机型:20pt
X:44pt
所以加上navigaitonbar的高度是
其他机型:64
X:88
可以用下面的代码获取statusBar的高度:

//获取tabbar的高度
[[UIApplication sharedApplication] statusBarFrame].size.height]
//获取navigaitonbar的高度
 CGRect rectOfNavigationbar = self.navigationController.navigationBar.frame;
    NSLog(@"navigationbar的高度: %f", rectOfNavigationbar.size.height);  

进行宏定义
/**
 适配iPhoneX
 */
#define KStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
#define kNavBarHeight 44.0
#define kTabBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height>20?83:49)
#define kTopHeight (KStatusBarHeight + kNavBarHeight)


3、屏幕底部

因为没有了 Home 键,iPhone X 的底部是预留给系统功能的一个区域
Home Indicator:34pt
所以tabbar的高度:
其他机型:49pt
X:34+49 = 83
代码获取高度

//在tabBarController中使用(你的继承自UITabBarController的VC)
CGFloat tabBarHeight = self.tabBar.frame.size.height;
//在非tabBarController中使用
UITabBarController *tabBarVC = [[UITabBarController alloc] init];(这儿取你当前tabBarVC的实例)
CGFloat tabBarHeight = tabBarVC.tabBar.frame.size.height;
3、安全区域

参考文章:
iPhone X 适配(全)

相关文章

网友评论

      本文标题:ios11和iphoneX的适配笔记

      本文链接:https://www.haomeiwen.com/subject/hracjftx.html