关于iOS 11的一些新特性适配实践总结

2020-01-21 02:15:03王旭


@property(nonatomic,assign) BOOL automaticallyAdjustsScrollViewInsets

在IOS11的SDK下,UIScrollView的这个属性


@property(nonatomic) UIScrollViewContentInsetAdjustmentBehavior contentInsetAdjustmentBehavior //这个属性是一个枚举类型的

{

UIScrollViewContentInsetAdjustmentAutomatic,//scrollView会自动计算和适应顶部和底部的内边距并且在scrollView 不可滚动时,也会设置内边距.

UIScrollViewContentInsetAdjustmentScrollableAxes, //自动适应边距

UIScrollViewContentInsetAdjustmentNever, //和 automaticallyAdjustsScrollViewInsets=NO有着同样的效果,不计算内边距

UIScrollViewContentInsetAdjustmentAlways//根据safeAreaInsets (安全区域)计算内边距

 }

所以,在IOS 11 下,需要设置ScrollView:


 self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;

如果需要全局设置的话,需要这么设置:


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

 

 [[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];

}

这样设置后使用UITableview 、UICollectionView、UIScrollview的时候就不需要再单独设置该属性了,因为UIView以及他的子类都是遵循UIAppearance协议的。

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对ASPKU的支持。

Reference

Positioning Content Within Layout Margins directionalLayoutMargins systemMinimumLayoutMargins SafeAreaInsets
注:相关教程知识阅读请移步到IOS开发频道。