ios 11 上tableview 改动

1、 UIViewController的automaticallyAdjustsScrollViewInsets属性被废弃。需要使用UIScrollView的contentInsetAdjustmentBehavior来替代。 关于 contentInsetAdjustmentBehavior

typedef NS_ENUM(NSInteger, UIScrollViewContentInsetAdjustmentBehavior) {
    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
    UIScrollViewContentInsetAdjustmentScrollableAxes, // Edges for scrollable axes are adjusted (i.e., contentSize.width/height > frame.size.width/height or alwaysBounceHorizontal/Vertical = YES)
    UIScrollViewContentInsetAdjustmentNever, // contentInset is not adjusted
    UIScrollViewContentInsetAdjustmentAlways, // contentInset is always adjusted by the scroll view's safeAreaInsets
} API_AVAILABLE(ios(11.0),tvos(11.0));
  • UIScrollViewContentInsetAdjustmentAutomatic 滚动视图会自动计算和适应顶部和底部的内边距并且在滚动视图不可滚动时,也会设置内边距

  • UIScrollViewContentInsetAdjustmentScrollableAxes 自动计算内边距。

    *UIScrollViewContentInsetAdjustmentNever 不计算内边距

    *UIScrollViewContentInsetAdjustmentAlways 根据safeAreaInsets计算内边距

if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else {
        self.automaticallyAdjustsScrollViewInsets = NO;
}

3、在philm项目中我需要把默认选中的滤镜自动移动到屏幕的中间时 直接使用:

//这样写 并不work
[self.filterListView scrollToRowAtIndexPath:self.selectedIndexPath
                                       atScrollPosition:UITableViewScrollPositionMiddle
                                               animated:NO];
// 加上0.1秒的延迟就好了   https://stackoverflow.com/questions/46075517/uitableview-scrolltorow-no-longer-works-on-ios-11-right-after-adding-a-new-row
  dispatch_after(dispatch_time(DISPATCH_TIME_NOW,     
   (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

        [self.filterListView scrollToRowAtIndexPath:self.selectedIndexPath
                                       atScrollPosition:UITableViewScrollPositionMiddle
                                               animated:NO];        
 });

Last updated