iOS|iOS iPhoneX 适配
一 iPhoneX各个视图值 1.简单定义一下IPoneX
_isIphoneX = [UIScreen mainScreen].bounds.size.height == 812 ? YES : NO;
2.了解IPhoneX各个视图的高度
- 状态栏 - statusBarHeight
- 导航栏 - navBarHeight
- tabBar
- 安全距离 - safeAreaBottomHeight
1.导航栏高度 88,非iPoneX手机为64代码如下
2.状态栏高度44,非iPoneX手机为20
3.tabar高度83,非iPhoneX手机为49
- AppEnvs.h
@interface AppEnvs : NSObject
#pragma mark - 相关变量值
@property(nonatomic, assign) int screenWidth;
// 屏幕宽度
@property(nonatomic, assign) int screenHeight;
// 屏幕高度
@property(nonatomic, assign) int statusBarHeight;
// 系统状态栏高度
@property(nonatomic, assign) int tabBarHeight;
// 系统TabBar高度 + 安全距离
@property(nonatomic, assign) int safeAreaBottomHeight;
//iPhone X 安全距离
@property(nonatomic, assign) int navBarHeight;
// 导航栏高度
@property(nonatomic, assign) int navHeight;
// 状态栏 + 导航栏
@property(nonatomic, assign) int screenHeightTabBar;
// 屏幕高度 - 状态栏 - 导航栏 - tabBar - 安全距离
@property(nonatomic, assign) int screenHeightTabBarNoNavBar;
// 屏高 - 状态栏高度 - tabBar - 安全距离
@property(nonatomic, assign) int screenHeightNoNavBar;
// 屏高 - 状态栏 - 导航栏 - 安全距离
@property(nonatomic, assign) int screenHeightNoStatusBar;
// 屏幕高度 - 状态栏#pragma mark - 机型
@property(nonatomic, assign) bool isIPhone4;
@property(nonatomic, assign) bool isIPhone5;
@property(nonatomic, assign) bool isIPhone6;
@property(nonatomic, assign) bool isIPhone6Plus;
@property(nonatomic, assign) bool isIPhoneBig;
@property(nonatomic, assign) bool isIphoneX;
@end
- AppEnvs.m
@implementation AppEnvs
- (instancetype)init {
self = [super init];
if (self) {
_screenWidth = [UIScreen mainScreen].bounds.size.width;
_screenHeight = [UIScreen mainScreen].bounds.size.height;
_statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;
_safeAreaBottomHeight = _screenHeight == 812.0 ? 34 : 0;
_navBarHeight = 44;
_navHeight = _navBarHeight + _statusBarHeight;
_tabBarHeight = ([[UIApplication sharedApplication] statusBarFrame].size.height > 20 ? 83 : 49);
_screenHeightNoNavBar = _screenHeight - _navHeight - _safeAreaBottomHeight;
_screenHeightTabBar = _screenHeight - _navHeight - _tabBarHeight;
_screenHeightTabBarNoNavBar = _screenHeight - _statusBarHeight - _tabBarHeight;
_screenHeightNoStatusBar = _screenHeight - _statusBarHeight;
// 机型
if (_screenHeight == 812) {
_isIphoneX = YES;
} else if (_screenWidth > 370 && _screenWidth < 400 && _screenHeight != 812) {
_isIPhone6 = YES;
} else if (_screenWidth > 400 && _screenHeight != 812) {
_isIPhone6Plus = YES;
} else if (_screenWidth == 320 && _screenHeight == 568) {
_isIPhone5 = YES;
} else if (_screenWidth == 320 && _screenHeight == 480) {
_isIPhone4 = YES;
}if (_screenWidth > 370) {
_isIPhoneBig = YES;
}
}
return self;
}
@end
运行结果
文章图片
image.png 附带iPhoneX和iPhone6的变量截图
- iPhoneX各个变量说明
- iPhone6各个变量说明
- 如有错误,欢迎指正,多多点赞,打赏更佳,您的支持是我写作的动力。
推荐阅读
- 2020-04-07vue中Axios的封装和API接口的管理
- iOS中的Block
- 记录iOS生成分享图片的一些问题,根据UIView生成固定尺寸的分享图片
- 2019-08-29|2019-08-29 iOS13适配那点事
- Hacking|Hacking with iOS: SwiftUI Edition - SnowSeeker 项目(一)
- iOS面试题--基础
- Android6.0~9.0适配
- 接口|axios接口报错-参数类型错误解决
- iOS|iOS 笔记之_时间戳 + DES 加密
- iOS,打Framework静态库