iOS11.0 scrollView|tableView向下偏移20

偏移的原因是之前使用的

self.automaticallyAdjustsScrollViewInsets = NO;

在iOS11中被弃用了
点开代码可以看到官方的解释

@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这个属性
使用方法:

...UITableView alloc] init]...
if (@available(iOS 11.0, *)) {
    tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else {
    // Fallback on earlier versions
 }

备注:
contentInsetAdjustmentBehavior --

/* Configure the behavior of adjustedContentInset.
 Default is UIScrollViewContentInsetAdjustmentAutomatic.
 */
@property(nonatomic) UIScrollViewContentInsetAdjustmentBehavior contentInsetAdjustmentBehavior API_AVAILABLE(ios(11.0),tvos(11.0));

推荐阅读更多精彩内容