iOS 11 与 iPhone X的适配那些事

本文针对iOS11发布后的应用适配问题,特别是iPhoneX的特殊设计进行了详细的解析。包括如何正确设置启动画面,解决UITableView的下拉刷新问题及调整高度计算等。此外还介绍了iOS11中NavigationBar的新特性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

9月20日,正式推送Xcode 9和iOS 11的正式版,适配iOS 11是首要的适配的,网上教程很多,不在赘述。这里主要讲的是iPhone X的适配大神级别的可以不用看,我这里讲的主要是基础的适配工作

  摘要

  启动图:1125 * 2436 
  statusBar高度:44 
  tabbar高度:83

  • 启动应用程序

对于一些老项目,在启动图上,可能没有采用XIB或者SB进行适配的,所以可能会出现如图一,这样导致整个项目运行就会不能完全贴合。

![上传login2_194373.png。 。 ]
![上传login2_194373.png。。]

解决办法,在项目设置里面直接用LaunchScreen.xib或者LaunchScreen.storyboard进行配置启动图,这样项目就会完整显示了

 

iPhone X LaunchImage.png
iPhone X LaunchImage.png

 

iPhone X LaunchImage2.png
iPhone X LaunchImage2.png
login2.png
    login2.png

出现下拉刷新的尾巴,该问题很好解决,在文档中标注很明白

1 @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
contentInsetAdjustmentBehavior对于我们现在来说是个陌生面孔。这是在iOS11为中ScrollView新定义的一个枚举属性。
注意,谈到上面的
automaticallyAdjustsScrollViewInsets的英文控制器的属性。
1 typedef NS_ENUM(NSInteger, UIScrollViewContentInsetAdjustmentBehavior) {
2     UIScrollViewContentInsetAdjustmentAutomatic, // Similar to .scrollableAxes, but for backward compatibility will also adjust the top & bottom contentInset when the scroll view is owned by a view controller with automaticallyAdjustsScrollViewInsets = YES inside a navigation controller, regardless of whether the scroll view is scrollable
3     UIScrollViewContentInsetAdjustmentScrollableAxes, // Edges for scrollable axes are adjusted (i.e., contentSize.width/height > frame.size.width/height or alwaysBounceHorizontal/Vertical = YES)
4     UIScrollViewContentInsetAdjustmentNever, // contentInset is not adjusted
5     UIScrollViewContentInsetAdjustmentAlways, // contentInset is always adjusted by the scroll view's safeAreaInsets
6 } API_AVAILABLE(ios(11.0),tvos(11.0));

 

iOS 11中的estimatedXXHeight由默认的0变成了现在的默认.AutomaticDimension,导致高度计算出错,最后导致的现象就是上拉加载更多的时候UI错乱,TableView视图的高度异常等一系列问题。

 1  if (@available(iOS 11.0, *)) {
 2         _newtableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
 3         //以下是tableview高度计算出现问题
 4         _newtableView.estimatedRowHeight = 0;
 5         _newtableView.estimatedSectionHeaderHeight=0;
 6         _newtableView.estimatedSectionFooterHeight=0;
 7         
 8   }else{
 9         self.automaticallyAdjustsScrollViewInsets = NO;
10   }

 

iOS 11 NavigationBar新特性

Navigation集成UISearchController
把你的UISearchController赋值给navigationItem,可以就实现将UISearchController集成到Navigation

1 navigationItem.searchController  //iOS 11 新增属性
2 navigationItem.hidesSearchBarWhenScrolling //决定滑动的时候是否隐藏搜索框;iOS 11 新增属性

 

@property (nonatomic, retain, nullable) UISearchController *searchController API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);

 

总结:

iOS11系统改变还是比较大的,某些地方需要注意适配,不然会出现很奇怪的现象。暂时,在iOS11遇到这么多坑,以后遇到会继续分享的。
第一次写文章,多谢关照

参考:

开发者所需要知道的iOS 11 SDK新特性
iOS 11导航栏高度自定义
iOS 11 UIKitの変更点

 

原文地址:http://www.jianshu.com/p/fed93b411eb6

转载于:https://www.cnblogs.com/ChocolateChen/p/7574149.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值