ios 11 아이 폰 x 와 관련 된 적합 한 문제 및 해결 방법

8820 단어 iosiphonexios11
iOS 11 에 관 한 가장 큰 변 화 는 안전 구역(safeArea)이라는 개념 을 증가 시 켰 다 는 것 이다.iOS 11 이 적합 한 대부분의 문 제 는 이 로 인해 발생 한 것 이다.
ios 11 에서 table View 는 알 수 없 는 오프셋,해결 방법:

//  iOS11 tableview     ,       0 
 self.tableView.estimatedRowHeight = 0; 
 self.tableView.estimatedSectionHeaderHeight = 0; 
 self.tableView.estimatedSectionFooterHeight = 0; 
scrollView 를 해결 합 니 다.기본 위치 가 바 뀌 었 습 니 다.해결 방법:

-(void)setScrollViewContentInsetAdjustmentBehavior:(UIScrollView *)scrollView { 
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 
 if(@available(iOS 11.0, *)) { 
  if ([scrollView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) { 
   scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; 
  } 
 } 
#endif 
} 
아이 폰 x 어댑터 에 대해 클래스 를 봉 인 했 습 니 다.코드 는 다음 과 같 습 니 다.
ScreenTool.h

#import <Foundation/Foundation.h> 
#import <UIKit/UIKit.h> 
#define ViewSafeAreaInsets(view) [ScreenToolSharedInstance getViewSafeAreaInsets:view] 
#define WindowSafeAreaInsets [ScreenToolSharedInstance getWindowSafeAreaInsets] 
#define Screen_height [[UIScreen mainScreen] bounds].size.height 
#define Screen_width [[UIScreen mainScreen] bounds].size.width 
#define ScreenToolSharedInstance [ScreenTool sharedInstance] 
#define NavAndStatusBarHeight [ScreenToolSharedInstance getNavAndStatusBarHeight] 
#define TabBarAndVirtualHomeHeight [ScreenToolSharedInstance getTabBarAndVirtualHomeHeight] 
#define StatusBarHeight [ScreenToolSharedInstance getStatusBarHeight] 
#define NavContentHeight [ScreenToolSharedInstance getNavContentHeight] 
#define TabBarContentHeight [ScreenToolSharedInstance getTabBarContentHeight] 
#define ScrollViewContentInsetAdjustmentBehavior(scrollView) [ScreenToolSharedInstance setScrollViewContentInsetAdjustmentBehavior:scrollView] 
typedef NS_ENUM(NSUInteger, DeviceScreenType) {//       
 DeviceTypeIphone4Screen, 
 DeviceTypeIphone5Screen, 
 DeviceTypeIphone6Screen, 
 DeviceTypeIphone6PlusScreen, 
 DeviceTypeIphoneXScreen, 
 DeviceTypeOtherScreen 
}; 
typedef NS_ENUM(NSUInteger, DeviceOrientationType) {//       
 DeviceOrientationTypeHorizontalScreen, 
 DeviceOrientationTypeVerticalScreen, 
 DeviceOrientationTypeOther 
}; 
@interface ScreenTool : NSObject 
@property(nonatomic,unsafe_unretained)BOOL isAccordingToSafeArea; 
-(void)setScrollViewContentInsetAdjustmentBehavior:(UIScrollView *)scrollView; 
+(ScreenTool *)sharedInstance; 
+(BOOL)isSmallScreen; 
-(UIEdgeInsets)getWindowSafeAreaInsets; 
-(UIEdgeInsets)getViewSafeAreaInsets:(UIView *)view; 
-(NSString *)getDevice; 
-(DeviceScreenType)getDeviceType; 
-(DeviceOrientationType)getDeviceOrientationType; 
-(CGFloat)getNavAndStatusBarHeight; 
-(CGFloat)getTabBarAndVirtualHomeHeight; 
-(CGFloat)getTabBarContentHeight; 
-(CGFloat)getNavContentHeight; 
-(CGFloat)getStatusBarHeight; 
@end 
ScreenTool.m
[objc] view plain copy
#import "ScreenTool.h" 
@implementation ScreenTool 
-(instancetype)init{ 
 if (self = [super init]) { 
  self.isAccordingToSafeArea = YES; 
 } 
 return self; 
} 
+(ScreenTool *)sharedInstance { 
 static dispatch_once_t pred = 0; 
 __strong static id screenTool = nil; 
 dispatch_once(&pred, ^{ 
  screenTool = [[self alloc] init]; 
 }); 
 return screenTool; 
} 
-(void)setScrollViewContentInsetAdjustmentBehavior:(UIScrollView *)scrollView { 
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 
 if(@available(iOS 11.0, *)) { 
  if ([scrollView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) { 
   scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; 
  } 
 } 
#endif 
} 
-(UIEdgeInsets)getWindowSafeAreaInsets { 
 UIEdgeInsets i = UIEdgeInsetsZero; 
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 
 if(@available(iOS 11.0, *)) { 
  i = [UIApplication sharedApplication].keyWindow.safeAreaInsets; 
 } 
#endif 
 return i; 
} 
-(UIEdgeInsets)getViewSafeAreaInsets:(UIView *)view { 
 UIEdgeInsets i = UIEdgeInsetsZero; 
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 
 if(@available(iOS 11.0, *)) { 
  i = view.safeAreaInsets; 
 } 
#endif 
 return i; 
} 
-(NSString *)getDevice { 
 if ((Screen_width == 320 && Screen_height == 480) || (Screen_height == 320 && Screen_width == 480)) { 
  return @"4"; 
 }else if ((Screen_width == 320 && Screen_height == 568) || (Screen_height == 320 && Screen_width == 568)) { 
  return @"5"; 
 }else if ((Screen_width == 375 && Screen_height == 667) || (Screen_height == 375 && Screen_width == 667)) { 
  return @"6"; 
 }else if ((Screen_width == 375 && Screen_height == 812) || (Screen_height == 375 && Screen_width == 812)) { 
  return @"x"; 
 }else if ((Screen_width == 414 && Screen_height == 736) || (Screen_height == 414 && Screen_width == 736)) { 
  return @"6p"; 
 }else { 
  return @""; 
 } 
} 
-(DeviceScreenType)getDeviceType { 
 if ((Screen_width == 320 && Screen_height == 480) || (Screen_height == 320 && Screen_width == 480)) { 
  return DeviceTypeIphone4Screen; 
 }else if ((Screen_width == 320 && Screen_height == 568) || (Screen_height == 320 && Screen_width == 568)) { 
  return DeviceTypeIphone5Screen; 
 }else if ((Screen_width == 375 && Screen_height == 667) || (Screen_height == 375 && Screen_width == 667)) { 
  return DeviceTypeIphone6Screen; 
 }else if ((Screen_width == 375 && Screen_height == 812) || (Screen_height == 375 && Screen_width == 812)) { 
  return DeviceTypeIphoneXScreen; 
 }else if ((Screen_width == 414 && Screen_height == 736) || (Screen_height == 414 && Screen_width == 736)) { 
  return DeviceTypeIphone6PlusScreen; 
 }else { 
  return DeviceTypeOtherScreen; 
 } 
} 
-(DeviceOrientationType)getDeviceOrientationType { 
 if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) { 
  return DeviceOrientationTypeVerticalScreen; 
 } else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight) { 
  return DeviceOrientationTypeHorizontalScreen; 
 }else { 
  return DeviceOrientationTypeOther; 
 } 
} 
+(BOOL)isSmallScreen{ 
 if (Screen_width >=375 && Screen_height >= 667) { 
  return NO; 
 }else { 
  return YES; 
 } 
} 
-(CGFloat)getTabBarContentHeight { 
 if (!UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsZero, WindowSafeAreaInsets)) { 
  //if ([self getDeviceType] == DeviceTypeIphoneXScreen) { 
  if ([self getDeviceOrientationType] == DeviceOrientationTypeHorizontalScreen) { 
   if (self.isAccordingToSafeArea) { 
    return 32; 
   }else { 
    return 49; 
   } 
  }else { 
   return 49; 
  } 
 }else { 
  return 49; 
 } 
} 
-(CGFloat)getNavContentHeight { 
 if (!UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsZero, WindowSafeAreaInsets)) { 
  // } 
  // if ([self getDeviceType] == DeviceTypeIphoneXScreen) { 
  if ([self getDeviceOrientationType] == DeviceOrientationTypeHorizontalScreen) { 
   if (self.isAccordingToSafeArea) { 
    return 32; 
   }else { 
    return 44; 
   } 
  }else { 
   return 44; 
  } 
 }else { 
  return 44; 
 } 
} 
-(CGFloat)getStatusBarHeight { 
 return [[UIApplication sharedApplication] statusBarFrame].size.height; 
} 
-(CGFloat)getNavAndStatusBarHeight { 
 return [self getNavContentHeight]+[self getStatusBarHeight]; 
} 
-(CGFloat)getTabBarAndVirtualHomeHeight { 
 return [self getTabBarContentHeight]+WindowSafeAreaInsets.bottom; 
} 
@end 
총결산
위 에서 말 한 것 은 소 편 이 여러분 에 게 소개 한 ios 11 과 아이 폰 x 의 관련 적합 한 문제 와 해결 방법 입 니 다.여러분 에 게 도움 이 되 기 를 바 랍 니 다.궁금 한 점 이 있 으 시 면 저 에 게 메 시 지 를 남 겨 주세요.소 편 은 제때에 답 해 드 리 겠 습 니 다.여기 서도 저희 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!

좋은 웹페이지 즐겨찾기