iOS UITableview 在编辑时更新tableview的高度

47 阅读1分钟

UITableview 在 editing == YES 时,是不能修改 tableview 的frame,强制修改会造成不可控的问题。 所以如果要在editing时修改高度,可以设置tableView的tableFooterView来实现。

if (show) {
        bottomViewFrame = CGRectMake(bottomViewLeftRightMarge, bottomViewY, bottomViewWidth, bottomViewHeight);
        [self.bottomView animatePositionWithKeyframes:bottomViewFrame];
        
        self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, (bottomViewHeight))];
    } else {
        [self.bottomView animatePositionWithKeyframes:bottomViewFrame];
        self.tableView.tableFooterView = [[UIView alloc] init];
        [self.tableView setContentOffset:CGPointMake(self.tableView.contentOffset.x, MAX(0, self.tableView.contentOffset.y-99))];
    }