SizeMacroHeader.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // SizeMacroHeader.h
  3. // MIT_Shop
  4. //
  5. // Created by 翟玉磊 on 2017/9/5.
  6. // Copyright © 2017年 翟玉磊. All rights reserved.
  7. //
  8. #ifndef SizeMacroHeader_h
  9. #define SizeMacroHeader_h
  10. //尺寸相关的宏
  11. /// 类型相关
  12. #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  13. #define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  14. #define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
  15. /// 手机类型相关
  16. #define IS_IPHONE_4_OR_LESS (IS_IPHONE && VIEW_BOUNDS_HEIGHT < 568.0)
  17. #define IS_IPHONE_5 (IS_IPHONE && VIEW_BOUNDS_HEIGHT == 568.0)
  18. #define IS_IPHONE_6 (IS_IPHONE && VIEW_BOUNDS_HEIGHT == 667.0)
  19. #define IS_IPHONE_6P (IS_IPHONE && VIEW_BOUNDS_HEIGHT == 736.0)
  20. #define IS_IPHONE_X (IS_IPHONE && isIPhoneXSeries())
  21. /// 圆角角度
  22. #define CORNER_RADIUS 2.0f
  23. /// 边距间隔
  24. #define SPACING_EDGE 20.0f
  25. /// 按钮高度
  26. #define BUTTON_HEIGHT 50.0f
  27. /// 全局细线高度
  28. #define LINE_HEIGHT 0.55f
  29. /// 状态栏高低
  30. #define STATUS_HEIGHT (IS_IPHONE_X ? 44.0 : 20.0)
  31. /// 导航控制器高度 + 状态栏高度
  32. #define NAVGATION_HEIGHT (IS_IPHONE_X ? 88.0 : 64.0)
  33. /// 底部tabbar高度
  34. #define TABBAR_HEIGHT (IS_IPHONE_X ? 83.0 : 49.0)
  35. /// home indicator
  36. #define HOME_INDICATOR_HEIGHT (IS_IPHONE_X ? 34.0 : 0.0)
  37. /// 宽度比例
  38. #define VWIDTH ([[UIScreen mainScreen] bounds].size.width /375.0)
  39. #define VWIDTH_X ([[UIScreen mainScreen] bounds].size.width /414.0)
  40. /// 高度比例
  41. #define VHEIGHT ([[UIScreen mainScreen] bounds].size.height /667.0)
  42. #define VHEIGHT_X ([[UIScreen mainScreen] bounds].size.height /896.0)
  43. #define SCREEN_BOUNDS ([[UIScreen mainScreen] bounds])
  44. /// 屏幕高度(安全区域)
  45. #define VIEW_BOUNDS_HEIGHT ([UIScreen mainScreen].bounds.size.height - HOME_INDICATOR_HEIGHT)
  46. /// 屏幕高度
  47. #define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
  48. /// 屏幕宽度
  49. #define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
  50. /// 导航控制器高度
  51. #define NAVIGATIONHEIGHT self.navigationController.navigationBar.frame.size.height
  52. /// 导航控制器宽度
  53. #define NAVIGATIONWIDTH self.navigationController.navigationBar.frame.size.width
  54. /// 状态栏高度
  55. #define STATUSHEIGHT [UIApplication sharedApplication].statusBarFrame.size.height
  56. /// 状态栏宽度
  57. #define STATUSWIDTH [UIApplication sharedApplication].statusBarFrame.size.width
  58. /// 常用的frame
  59. #define COMMON_FRAMER CGRectMake(0, NAVGATION_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - NAVGATION_HEIGHT)
  60. /*
  61. * 鉴于iPhone X/XS/XR/XS Max底部都会有安全距离,所以可以利用safeAreaInsets.bottom > 0.0来判断是否是iPhone X/XS/XR/XS Max,safeAreaInsets支持iOS11及以后。
  62. */
  63. static inline BOOL isIPhoneXSeries() {
  64. BOOL iPhoneXSeries = NO;
  65. if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) {
  66. return iPhoneXSeries;
  67. }
  68. if (@available(iOS 11.0, *)) {
  69. UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
  70. if (mainWindow.safeAreaInsets.bottom > 0.0) {
  71. iPhoneXSeries = YES;
  72. }
  73. }
  74. return iPhoneXSeries;
  75. }
  76. /// 适配各种机型
  77. /// 界面主视图是scrollView、tabelView
  78. /// viewdidload添加
  79. //#ifdef __IPHONE_11_0
  80. //if (@available(iOS 11.0, *)) {
  81. // /// CoderMikeHe: 适配 iPhone X + iOS 11,
  82. // AdjustsScrollViewInsets_Never(self.tableView);
  83. // /// iOS 11上发生tableView顶部有留白,原因是代码中只实现了heightForHeaderInSection方法,而没有实现viewForHeaderInSection方法。那样写是不规范的,只实现高度,而没有实现view,但代码这样写在iOS 11之前是没有问题的,iOS 11之后应该是由于开启了估算行高机制引起了bug。
  84. // self.tableView.estimatedRowHeight = 0;
  85. // self.tableView.estimatedSectionHeaderHeight = 0;
  86. // self.tableView.estimatedSectionFooterHeight = 0;
  87. //}
  88. //#endif
  89. ///如果是masonry则添加下面的约束
  90. //if (@available(iOS 11.0, *)) {
  91. // make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
  92. // make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  93. //} else {
  94. // make.top.equalTo(self.view.mas_top).offset(NAVGATION_HEIGHT);
  95. // make.bottom.equalTo(self.view.mas_bottom);
  96. //}
  97. ///如果是frame则添加 滚动视图的frame设置成[UIScreen mainScreen].bounds和contentInset = UIEdgeInsetsMake(NAVGATION_HEIGHT, 0, 0, 0);
  98. #pragma mark - 全局枚举
  99. #endif /* SizeMacroHeader_h */