iOS 10.3.3 , tableView 布局有问题,tableView 有一个突然的偏移

iOS 10.3.3 , tableView 布局有问题,如下图,tableView 有一个突然的偏移。

9ioac.png

代码如下:

- (void)viewWillLayoutSubviews{

    self.tableView.translatesAutoresizingMaskIntoConstraints = NO;
    [super viewWillLayoutSubviews];
    [self.tableView.bottomAnchor constraintEqualToAnchor: self.view.bottomAnchor constant: -52].active = YES;
    [self.tableView.leadingAnchor constraintEqualToAnchor: self.view.leadingAnchor].active = YES;
    [self.tableView.trailingAnchor constraintEqualToAnchor: self.view.trailingAnchor].active = YES;
    [self.tableView.topAnchor constraintEqualToAnchor: self.view.topAnchor constant: 75].active = YES;
 }

设置了 self.automaticallyAdjustsScrollViewInsets, 不起作用。

- (void)viewDidLoad {
    [super viewDidLoad];
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
         self.automaticallyAdjustsScrollViewInsets = NO;
    }
}

在 iOS 11.4, 布局正常。

怎样解决呢?

阅读 3k
1 个回答
新手上路,请多包涵

重新编辑下问题吧,不知道是不是刷新出了问题不,如果是刷新出了问题,可以使用

self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题