iOS 11安全区域对UIScrollview和UITableView的影响

UITableView:

UITableView里边添加了一个属性insetsContentViewsToSafeArea,默认值是YES,从字面意思很容易理解,他的内容是在安全区域中的。这样做有什么好处吗?这可以保证:我们可以看清楚表格里边的内容,而不会被下边的指示条遮挡。其实他就是增加了自己contentView的size实现的。

@property (nonatomic) BOOL insetsContentViewsToSafeArea API_AVAILABLE(ios(11.0), tvos(11.0)); // default value is YES

效果如下:


iOS 11安全区域对UIScrollview和UITableView的影响_第1张图片
上边增加content


iOS 11安全区域对UIScrollview和UITableView的影响_第2张图片
下边增加content

现在谈论一下:

1.安全区域会对iOS8的用户产生影响吗?

首先如果你适配iOS8,那么安全区域你根本不可以使用,根本编译不过去。

2.安全区域会对iOS11的iPhone6产生影响吗?

iOS11之前写的代码,没有安全区域(例如,XIB中都没有安全区域这个东西),但是用户升级iOS11之后,对于以前XIB写的布局,由于没有启用安全区域布局,但是也不会受到影响,因为UITableView自带了上边这个属性,不会导致遮挡。

UIScrollview

//When contentInsetAdjustmentBehavior allows, UIScrollView may incorporateits safeAreaInsets into the adjustedContentInset.

@property(nonatomic, readonly) UIEdgeInsets adjustedContentInset API_AVAILABLE(ios(11.0),tvos(11.0));

//Default is UIScrollViewContentInsetAdjustmentAutomatic.

@property(nonatomic) UIScrollViewContentInsetAdjustmentBehavior contentInsetAdjustmentBehavior API_AVAILABLE(ios(11.0),tvos(11.0));

typedef NS_ENUM(NSInteger, UIScrollViewContentInsetAdjustmentBehavior) {

//自动调整内边距,当滚动视图作为带导航和tabbar的控制器的子视图并且被竖直显示的时候,总是会被调整;如果滚动视图水平滚动,滚动内容的offset也会被调整到非0区域。

UIScrollViewContentInsetAdjustmentAutomatic, 

//在多方向滚动的时候,调整内边距。顶部和底部的内边距包含了安全区域的值

UIScrollViewContentInsetAdjustmentScrollableAxes, 

//内边距从来不要调整,默认总是(0,0,0,0)

UIScrollViewContentInsetAdjustmentNever, 

//contentInset is always adjusted by the scroll view's safeAreaInsets。内边距总是被调整到安全区域

UIScrollViewContentInsetAdjustmentAlways, 

} API_AVAILABLE(ios(11.0),tvos(11.0));

你可能感兴趣的:(iOS 11安全区域对UIScrollview和UITableView的影响)