iOS11遇到的坑及解决方法

1、iOS 11之前的导航栏的高度是64px(状态条+导航栏),iOS11之后如果设置了prefersLargeTitles = YES(默认NO)则为96pt。所以一般不用管。

2、在iOS 11上运行tableView向下偏移64px或者20px,因为iOS 11废弃了automaticallyAdjustsScrollViewInsets,而是给UIScrollView增加了contentInsetAdjustmentBehavior属性。避免这个坑的方法是要判断

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

_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;

}else {

self.automaticallyAdjustsScrollViewInsets = NO;

}

3、tableView的sectionHeader、sectionFooter高度与设置不符,因为tableView的estimatedRowHeight、estimatedSectionHeaderHeight、 estimatedSectionFooterHeight三个高度估算属性由默认的0变成了UITableViewAutomaticDimension。最简单的方法就是直接设置为0。


4、iPhone X状态条由20px变成了44px,UITabBar由49px变成了83px。设置布局时y直接写成64的就要根据机型设置。可以设置宏

#define Device_Is_iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO),

然后再设置。


5.IOS11 之前,不想让scrollView偏移64px,设置automaticallyAdjustsScrollViewInsets=NO就可以了。IOS11以后就废弃了,使用scrollView的属性contentInsetAdjustmentBehavior来防止偏移。

UIScrollViewContentInsetAdjustmentAutomatic

UIScrollViewContentInsetAdjustmentScrollableAxes

UIScrollViewContentInsetAdjustmentNever

UIScrollViewContentInsetAdjustmentAlways

这里我们直接选Never就可以了

这里要注意的是,需要判断当前系统

//ios11 设置scrollView偏移

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

_scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;

}else {

self.automaticallyAdjustsScrollViewInsets = NO;

}



6.navigation bar 的titleView支持了autolayout,需要titleView自己撑开或者重写了- intrinsicContentSize方法。intrinsicContentSize顾名思义,固定大小的意思,主要是解决一些模糊约束的问题。更多知识可以看这篇文章详解intrinsicContentSize

不做适配在IOS11会遇到的问题:

titleView对应的View大小和预期不一致。

titleView对应的View有点击事件会无法触发

解决方法是直接重写titleView对应View的intrinsicContentSize方法

- (CGSize)intrinsicContentSize {

return UILayoutFittingExpandedSize;

}


7.在IOS11,原有的NSLocationAlwaysUsageDeion被降级为NSLocationWhenInUseUsageDeion。因此,在原来项目中使用requestAlwaysAuthorization获取定位权限,而未在plist文件中配置NSLocationAlwaysAndWhenInUseUsageDeion,系统框不会弹出。建议新旧key值都在plist里配置,反正我试下来是没有问题,唯一的区别是使用requestAlwaysAuthorization获取权限 IOS11系统弹框会把几种权限级别全部列出,供用户选择,显然更人性化了哈~~

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容