ios 11 上tableview 改动

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;
}

2、iOS 11中如果不实现-tableView: viewForFooterInSection:-tableView: viewForHeaderInSection:,那么-tableView: heightForHeaderInSection:- tableView: heightForFooterInSection:不会被调用。
这是因为estimatedRowHeight estimatedSectionHeaderHeight estimatedSectionFooterHeight三个高度估算属性由默认的0变成了UITableViewAutomaticDimension,导致高度计算不对,解决方法是实现对应方法或吧这三个属性设为0。
下面这个列表显示不全也是estimatedRowHeight引起,取contentSize出错。

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];        
 });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值