iOS11、iPhone X适配

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yyyyccll/article/details/91380119

iOS11、iPhone X适配
参考: https://www.jianshu.com/p/3a9ad4f0fa32?appinstall=0

参考网址笔记:
①iPhone X的状态栏由原来的20变为44
②iPhone X:375x812 @3x ,和6、6s宽度一样,但是高度比6、6s plus 还要高

——————————————————————————————————
一:具体的数值
//判断是否iPhone X
#define iSIPHONEX (kWJScreenHeight >= 812.0 ? 88 : 64
)

//iPhoneX头部偏移量
#define iPhoneX_Top_Space (iPhoneX ? 24.f : 0)

//iPhoneX底部偏移量
#define iPhoneX_Bottom_Space (iPhoneX ? 34.f : 0)

//顶部导航栏高度
#define NAV_HEIGHT (64+iPhoneX_Top_Space)

// Frame布局
tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, NAV_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - NAV_HEIGHT-iPhoneX_Bottom_Space) style:UITableViewStylePlain];

二:在iOS11中为View新增加了属性safeAreaLayoutGuide,在使用Auto Layout布局的时候,我们可以使用safeAreaLayoutGuide来创建约束

(1)swift版本:tableView
view.addSubview(tableView)
tableView.snp.makeConstraints {
$0.left.right.equalToSuperview()
$0.top.equalToSuperview()
if #available(iOS 11.0, *) {
$0.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
} else {
$0.bottom.equalToSuperview()
}
}

(2)oc版本:navBar
[self.view addSubview:self.navBar];
[self.navBar mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.right.equalTo(self.view);
if (@available(iOS 11.0, *)) {
make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(44);
} else {
make.height.equalTo(@64);
}
}];

猜你喜欢

转载自blog.csdn.net/yyyyccll/article/details/91380119