ios新版本特性与适配iOS高质量博客App适配

有关iOS11和iPhoneX的适配问题

2017-09-24  本文已影响26110人  苏东没有坡

一:iOS11 问题

有关iOS11 ,最大的变化就是增加了一个安全区域(safeArea)的概念,iOS11 适配的大部分问题都是由于它引起的。
如果还不太了解概念,推荐阅读 iOS 11 安全区域适配总结这篇文章。

1. tableView 头部视图和尾部视图出现一块留白问题

  self.tableView.estimatedRowHeight = 0;
  self.tableView.estimatedSectionHeaderHeight = 0;
  self.tableView.estimatedSectionFooterHeight = 0;

2. TableView 上拉刷新reloadData 时视图发生偏移

举个例子,我们加载数据分页一页10条数据,当我们上拉刷新请求第二页的时候,我们希望的是视图流畅地展示第11个cell的一部分,然后当前页面仅仅展示第10个cell,甚至会向上偏移一点。
这个问题也是iOS11 估算行高引起的问题,关闭估算行高

  self.tableView.estimatedRowHeight = 0;
  self.tableView.estimatedSectionHeaderHeight = 0;
  self.tableView.estimatedSectionFooterHeight = 0;

3. NavigationBar 的变化

  - (CGSize)intrinsicContentSize {
      return UILayoutFittingExpandedSize;
  }

4 .iOS 11 权限问题

iOS11对相册的权限key做了调整,将原来的 NSPhotoLibraryUsageDescription改成了NSPhotoLibraryAddUsageDescription。详见:Cocoa Keys

4. iOS11系统下SVProgessHUD默认的loading文字变灰问题

屏幕快照 2017-10-11 上午11.43.46.png

具体原因还未找到,坐等更新,暂时使用了SVP的自定义样式解决,望有遇到过的大佬不吝指教

  [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];//设置loading样式,默认白底黑字
  [SVProgressHUD setBackgroundColor:HEXCOLOR(0xf9f9f9ff)]; //设置loading底部背景颜色

二: iPhoneX问题

1. 适配iPhoneX的时候上面流海的屏幕仍是黑色,内容没有充满屏幕

{
    "extent" : "full-screen",
    "idiom" : "iphone",
    "subtype" : "2436h",
    "filename" : "你的启动图名字.png",
    "minimum-system-version" : "11.0",
    "orientation" : "portrait",
    "scale" : "3x"
}
2.webView,tableView页面无导航栏时,顶部出现44高度的空白
image.png

*iOS11中废弃了automaticallyAdjustsScrollViewInsets,取而代之的是contentInsetAdjustmentBehavior属性,adjustedContentInset属性决定了tableView与边缘的距离。iPhone X竖屏时控制器视图的safeAreaInsets是(44,0,34,0)

#pragma mark -- 废弃了的automaticallyAdjustsScrollViewInsets
@property(nonatomic,assign) BOOL automaticallyAdjustsScrollViewInsets API_DEPRECATED_WITH_REPLACEMENT
("Use UIScrollView's contentInsetAdjustmentBehavior instead", ios(7.0,11.0),tvos(7.0,11.0)); // Defaults to YES

#pragma mark -- UIScrollView新属性
/* When contentInsetAdjustmentBehavior allows, UIScrollView may incorporate
 its safeAreaInsets into the adjustedContentInset.
 */
@property(nonatomic, readonly) UIEdgeInsets adjustedContentInset API_AVAILABLE(ios(11.0),tvos(11.0));

contentInsetAdjustmentBehavior属性有以下几个枚举值:

/*
1. automatic 和scrollableAxes一样,scrollView会自动计算和适应顶部和底部的内边距并且在scrollView 不可滚动时,也会设置内边距.
2. scrollableAxes 自动计算内边距.
3. never 不计算内边距
4. always 根据safeAreaInsets 计算内边距
*/
typedef NS_ENUM(NSInteger, UIScrollViewContentInsetAdjustmentBehavior) {  
    UIScrollViewContentInsetAdjustmentAutomatic, 
    UIScrollViewContentInsetAdjustmentScrollableAxes,
    UIScrollViewContentInsetAdjustmentNever,
    UIScrollViewContentInsetAdjustmentAlways,
}

@property(nonatomic) UIScrollViewContentInsetAdjustmentBehavior contentInsetAdjustmentBehavior;
@property(nonatomic, readonly) UIEdgeInsets adjustedContentInset;

//adjustedContentInset值被改变的delegate
- (void)adjustedContentInsetDidChange; 
- (void)scrollViewDidChangeAdjustedContentInset:(UIScrollView *)scrollView;

添加如下代码解决问题

if (@available(iOS 11.0, *)) {
    tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
3.iPhoneX 在push进入 webView页面时,底部会有黑边一闪而过
if (@available(iOS 11.0, *)) {
    webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}

第一种方法会让webview的视图和底部有34的距离,第二种会使webview保持全屏,但一部分区域会被iPhoneX底下的黑条遮住,美丑自评

4.页面底部有固定的footerView被遮挡,以及一些自定义输入框弹起键盘被遮盖问题

iPhoneX需要将底部一些控件的位置往上移34,弹出的键盘隐藏时也可能会出现问题,根据实际情况修改。

5.视图高度问题

以前编写代码的时候,定义tableView高度可能只是用了SCREEN_HEIGHT-64-49(有tabbar的时候),也可能是SCREEN_HEIGHT-64(tabbar隐藏的时候),在iphoneX上面这样的写法会出现问题,特别是一些死页面,tableView会拉不到最底部。

参考
以上内容参考了以下文章,阅读原文请点击以下链接
iOS11 & iPhone X 适配指南 http://url.cn/5wjMhix
App界面适配iOS11 http://www.jianshu.com/p/352f101d6df1
iOS 11 安全区域适配总结 http://www.jianshu.com/p/efbc8619d56b

上一篇下一篇

猜你喜欢

热点阅读