ios 11 아이 폰 x 와 관련 된 적합 한 문제 및 해결 방법
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 의 관련 적합 한 문제 와 해결 방법 입 니 다.여러분 에 게 도움 이 되 기 를 바 랍 니 다.궁금 한 점 이 있 으 시 면 저 에 게 메 시 지 를 남 겨 주세요.소 편 은 제때에 답 해 드 리 겠 습 니 다.여기 서도 저희 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Swift의 패스트 패스Objective-C를 대체하기 위해 만들어졌지만 Xcode는 Objective-C 런타임 라이브러리를 사용하기 때문에 Swift와 함께 C, C++ 및 Objective-C를 컴파일할 수 있습니다. Xcode는 S...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.