// // SizeMacroHeader.h // MIT_Shop // // Created by 翟玉磊 on 2017/9/5. // Copyright © 2017年 翟玉磊. All rights reserved. // #ifndef SizeMacroHeader_h #define SizeMacroHeader_h //尺寸相关的宏 /// 类型相关 #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) #define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) #define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0) /// 手机类型相关 #define IS_IPHONE_4_OR_LESS (IS_IPHONE && VIEW_BOUNDS_HEIGHT < 568.0) #define IS_IPHONE_5 (IS_IPHONE && VIEW_BOUNDS_HEIGHT == 568.0) #define IS_IPHONE_6 (IS_IPHONE && VIEW_BOUNDS_HEIGHT == 667.0) #define IS_IPHONE_6P (IS_IPHONE && VIEW_BOUNDS_HEIGHT == 736.0) #define IS_IPHONE_X (IS_IPHONE && isIPhoneXSeries()) /// 圆角角度 #define CORNER_RADIUS 2.0f /// 边距间隔 #define SPACING_EDGE 20.0f /// 按钮高度 #define BUTTON_HEIGHT 50.0f /// 全局细线高度 #define LINE_HEIGHT 0.55f /// 状态栏高低 #define STATUS_HEIGHT (IS_IPHONE_X ? 44.0 : 20.0) /// 导航控制器高度 + 状态栏高度 #define NAVGATION_HEIGHT (IS_IPHONE_X ? 88.0 : 64.0) /// 底部tabbar高度 #define TABBAR_HEIGHT (IS_IPHONE_X ? 83.0 : 49.0) /// home indicator #define HOME_INDICATOR_HEIGHT (IS_IPHONE_X ? 34.0 : 0.0) /// 宽度比例 #define VWIDTH ([[UIScreen mainScreen] bounds].size.width /375.0) #define VWIDTH_X ([[UIScreen mainScreen] bounds].size.width /414.0) /// 高度比例 #define VHEIGHT ([[UIScreen mainScreen] bounds].size.height /667.0) #define VHEIGHT_X ([[UIScreen mainScreen] bounds].size.height /896.0) #define SCREEN_BOUNDS ([[UIScreen mainScreen] bounds]) /// 屏幕高度(安全区域) #define VIEW_BOUNDS_HEIGHT ([UIScreen mainScreen].bounds.size.height - HOME_INDICATOR_HEIGHT) /// 屏幕高度 #define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height /// 屏幕宽度 #define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width /// 导航控制器高度 #define NAVIGATIONHEIGHT self.navigationController.navigationBar.frame.size.height /// 导航控制器宽度 #define NAVIGATIONWIDTH self.navigationController.navigationBar.frame.size.width /// 状态栏高度 #define STATUSHEIGHT [UIApplication sharedApplication].statusBarFrame.size.height /// 状态栏宽度 #define STATUSWIDTH [UIApplication sharedApplication].statusBarFrame.size.width /// 常用的frame #define COMMON_FRAMER CGRectMake(0, NAVGATION_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - NAVGATION_HEIGHT) /* * 鉴于iPhone X/XS/XR/XS Max底部都会有安全距离,所以可以利用safeAreaInsets.bottom > 0.0来判断是否是iPhone X/XS/XR/XS Max,safeAreaInsets支持iOS11及以后。 */ static inline BOOL isIPhoneXSeries() { BOOL iPhoneXSeries = NO; if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) { return iPhoneXSeries; } if (@available(iOS 11.0, *)) { UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window]; if (mainWindow.safeAreaInsets.bottom > 0.0) { iPhoneXSeries = YES; } } return iPhoneXSeries; } /// 适配各种机型 /// 界面主视图是scrollView、tabelView /// viewdidload添加 //#ifdef __IPHONE_11_0 //if (@available(iOS 11.0, *)) { // /// CoderMikeHe: 适配 iPhone X + iOS 11, // AdjustsScrollViewInsets_Never(self.tableView); // /// iOS 11上发生tableView顶部有留白,原因是代码中只实现了heightForHeaderInSection方法,而没有实现viewForHeaderInSection方法。那样写是不规范的,只实现高度,而没有实现view,但代码这样写在iOS 11之前是没有问题的,iOS 11之后应该是由于开启了估算行高机制引起了bug。 // self.tableView.estimatedRowHeight = 0; // self.tableView.estimatedSectionHeaderHeight = 0; // self.tableView.estimatedSectionFooterHeight = 0; //} //#endif ///如果是masonry则添加下面的约束 //if (@available(iOS 11.0, *)) { // make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop); // make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom); //} else { // make.top.equalTo(self.view.mas_top).offset(NAVGATION_HEIGHT); // make.bottom.equalTo(self.view.mas_bottom); //} ///如果是frame则添加 滚动视图的frame设置成[UIScreen mainScreen].bounds和contentInset = UIEdgeInsetsMake(NAVGATION_HEIGHT, 0, 0, 0); #pragma mark - 全局枚举 #endif /* SizeMacroHeader_h */