ios 11和iphone x的相关适配问题及解决方法

  

有关iOS11,最大的变化就是增加了一个安全区域(safeArea)的概念,iOS11适配的大部分问题都是由于它引起的。

  

     //解决iOS11 tableview会出现漂移,预估高度都设为0   self.tableView.estimatedRowHeight=0;   self.tableView.estimatedSectionHeaderHeight=0;   self.tableView.estimatedSectionFooterHeight=0;之前   
     


  

        - (void) setScrollViewContentInsetAdjustmentBehavior: (UIScrollView *) scrollView {   #如果__IPHONE_OS_VERSION_MAX_ALLOWED祝辞=110000   如果(@available (iOS 11.0 *)) {   如果([scrollView respondstoselectorismemberofclass: @ selector (setContentInsetAdjustmentBehavior:))) {   滚动视图。contentInsetAdjustmentBehavior=UIScrollViewContentInsetAdjustmentNever;   }   }   # endif   }      


  

  

<强> ScreenTool。h
  

        # import & lt;基?Foundation.h>   # import & lt; UIKit/UIKit.h>   #定义ViewSafeAreaInsets(视图)[ScreenToolSharedInstance getViewSafeAreaInsets:视图)   #定义WindowSafeAreaInsets [ScreenToolSharedInstance getWindowSafeAreaInsets]   #定义Screen_height [[UIScreen mainScreen]范围].size.height   #定义Screen_width [[UIScreen mainScreen]范围].size.width   #定义ScreenToolSharedInstance [ScreenTool sharedInstance]   #定义NavAndStatusBarHeight [ScreenToolSharedInstance getNavAndStatusBarHeight]   #定义TabBarAndVirtualHomeHeight [ScreenToolSharedInstance getTabBarAndVirtualHomeHeight]   #定义StatusBarHeight [ScreenToolSharedInstance getStatusBarHeight]   #定义NavContentHeight [ScreenToolSharedInstance getNavContentHeight]   #定义TabBarContentHeight [ScreenToolSharedInstance getTabBarContentHeight]   #定义ScrollViewContentInsetAdjustmentBehavior(滚动视图)[ScreenToolSharedInstance setScrollViewContentInsetAdjustmentBehavior:滚动视图)   typedef NS_ENUM(了NSUInteger DeviceScreenType){//设备屏幕类型   DeviceTypeIphone4Screen,   DeviceTypeIphone5Screen,   DeviceTypeIphone6Screen,   DeviceTypeIphone6PlusScreen,   DeviceTypeIphoneXScreen,   DeviceTypeOtherScreen   };   typedef NS_ENUM(了NSUInteger DeviceOrientationType){//屏幕方向类型   DeviceOrientationTypeHorizontalScreen,   DeviceOrientationTypeVerticalScreen,   DeviceOrientationTypeOther   };   @ interface ScreenTool: NSObject   BOOL isAccordingToSafeArea @ property(原子unsafe_unretained);   - (void) setScrollViewContentInsetAdjustmentBehavior: (UIScrollView *)滚动视图;   + (ScreenTool *) sharedInstance;   + (BOOL) isSmallScreen;   ——(UIEdgeInsets) getWindowSafeAreaInsets;   ——(UIEdgeInsets) getViewSafeAreaInsets:(UIView *);   ——(NSString *) getDevice;   ——(DeviceScreenType) getDeviceType;   ——(DeviceOrientationType) getDeviceOrientationType;   ——(CGFloat) getNavAndStatusBarHeight;   ——(CGFloat) getTabBarAndVirtualHomeHeight;   ——(CGFloat) getTabBarContentHeight;   ——(CGFloat) getNavContentHeight;   ——(CGFloat) getStatusBarHeight;   @end   ScreenTool.m   普通副本(objc)视图   #进口“ScreenTool.h”   @ implementation ScreenTool   - (instancetype) init {   如果(自我=(超级init)) {   自我。isAccordingToSafeArea=是的;   }   回归自我;   }   + (ScreenTool *) sharedInstance {   静态dispatch_once_t pred=0;   强烈的静态id screenTool=零;   dispatch_once (, pred ^ {   screenTool=[[自我alloc] init);   });   返回screenTool;   }   - (void) setScrollViewContentInsetAdjustmentBehavior: (UIScrollView *) scrollView {   #如果__IPHONE_OS_VERSION_MAX_ALLOWED祝辞=110000   如果(@available (iOS 11.0 *)) {   如果([scrollView respondstoselectorismemberofclass: @ selector (setContentInsetAdjustmentBehavior:))) {   滚动视图。contentInsetAdjustmentBehavior=UIScrollViewContentInsetAdjustmentNever;   }   }   # endif   }   ——(UIEdgeInsets) getWindowSafeAreaInsets {   UIEdgeInsets我=UIEdgeInsetsZero;   #如果__IPHONE_OS_VERSION_MAX_ALLOWED祝辞=110000   如果(@available (iOS 11.0 *)) {   i=[UIApplication sharedApplication] .keyWindow.safeAreaInsets;   }   # endif   返回我;   }   ——(UIEdgeInsets) getViewSafeAreaInsets:视图(UIView *) {   UIEdgeInsets我=UIEdgeInsetsZero;   #如果__IPHONE_OS_VERSION_MAX_ALLOWED祝辞=110000   如果(@available (iOS 11.0 *)) {   我=view.safeAreaInsets;   }   # endif   返回我;   }   ——(NSString *) getDevice {   如果(Screen_width==320,,Screen_height==480) | | (Screen_height==320,,Screen_width==480)) {   回复@“4”;   }else if (Screen_width==320,,Screen_height==568) | | (Screen_height==320,,Screen_width==568)) {   回复@“5”;   }else if (Screen_width==375,,Screen_height==667) | | (Screen_height==375,,Screen_width==667)) {   回复@“6”;   }else if (Screen_width==375,,Screen_height==812) | | (Screen_height==375,,Screen_width==812)) {   回复@“x”;   }else if (Screen_width==414,,Screen_height==736) | | (Screen_height==414,,Screen_width==736)) {   回复@“6 p”;   其他}{   回复@ ";   }   }   ——(DeviceScreenType) getDeviceType {   如果(Screen_width==320,,Screen_height==480) | | (Screen_height==320,,Screen_width==480)) {   返回DeviceTypeIphone4Screen;   }else if (Screen_width==320,,Screen_height==568) | | (Screen_height==320,,Screen_width==568)) {   返回DeviceTypeIphone5Screen;   }else if (Screen_width==375,,Screen_height==667) | | (Screen_height==375,,Screen_width==667)) {   返回DeviceTypeIphone6Screen;   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

ios 11和iphone x的相关适配问题及解决方法