iOS11适配总结

iOS11系统tabbar高度适配

解决方法是,在Info.plist 里面增加  Launch screen interface file base name 就可以了。

注意:只是增加一个 key。Launch screen interface file base name

iPhone X Push 过程中 TabBar位置上移适配

在UINavigationController的基类重写pushViewController代理方法,在Push的时候修正一下TabBar的frame

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated

{

if (self.childViewControllers.count >= 1) {

viewController.hidesBottomBarWhenPushed = YES;

}

[super pushViewController:viewController animated:animated];

// 修正push控制器tabbar上移问题

if (@available(iOS 11.0, *)){

// 修改tabBra的frame

CGRect frame = self.tabBarController.tabBar.frame;

frame.origin.y = [UIScreen mainScreen].bounds.size.height - frame.size.height;

self.tabBarController.tabBar.frame = frame;

}

}

李明杰刷新适配


在AppDelegate里面添加下面的方法并调用

#pragma mark 适配iOS11

-(void)adaptationIOSSystem{

if (@available(iOS 11.0, *)) {

[[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];

// 去掉iOS11系统默认开启的self-sizing

[UITableView appearance].estimatedRowHeight = 0;

[UITableView appearance].estimatedSectionHeaderHeight = 0;

[UITableView appearance].estimatedSectionFooterHeight = 0;

}

}

跳转可编辑相册


出现列表显示不全

self.picker = [[UIImagePickerController alloc] init];//初始化self.picker.allowsEditing = YES;//设置可编辑

self.picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

self.picker.delegate = self;

[self presentViewController:self.picker animated:YES completion:nil];//进入相册界面


正是因为全局设置了UIScrollView.appearance.contentInsetAdjustmentBehavior,导致系统相册出现的问题(出现列表显示不全)

在进入的时候

if (@available(iOS 11, *)) {

UIScrollView.appearance.contentInsetAdjustmentBehavior =UIScrollViewContentInsetAdjustmentAutomatic;

}

在选择照片或退出时候

if (@available(iOS 11, *)) {

[UIScrollViewappearance].contentInsetAdjustmentBehavior =UIScrollViewContentInsetAdjustmentNever;

}


适配宏定义

// UIScreen width.

#define  LL_ScreenWidth  [UIScreen mainScreen].bounds.size.width

// UIScreen height.

#define  LL_ScreenHeight  [UIScreen mainScreen].bounds.size.height

// iPhone X

#define  LL_iPhoneX (LL_ScreenWidth == 375.f && LL_ScreenHeight == 812.f ? YES : NO)

// Status bar height.

#define  LL_StatusBarHeight      (LL_iPhoneX ? 44.f : 20.f)

// Navigation bar height.

#define  LL_NavigationBarHeight  44.f

// Tabbar height.

#define  LL_TabbarHeight        (LL_iPhoneX ? (49.f+34.f) : 49.f)

// Tabbar safe bottom margin.

#define  LL_TabbarSafeBottomMargin        (LL_iPhoneX ? 34.f : 0.f)

// Status bar & navigation bar height.

#define  LL_StatusBarAndNavigationBarHeight  (LL_iPhoneX ? 88.f : 64.f)

#define LL_ViewSafeAreInsets(view) ({UIEdgeInsets insets; if(@available(iOS 11.0, *)) {insets = view.safeAreaInsets;} else {insets = UIEdgeInsetsZero;} insets;})

推荐阅读更多精彩内容