调整视图的大小会使其他视图在UITableViewCell中反弹

问题描述 投票:1回答:1

我需要扩展或折叠表视图单元格及其内容。为此,我正在使用NSLayoutConstraints。尽管可以完成工作,但单元格中的其他视图仍面临一些令人讨厌的布局问题。Here is a video.这是我的代码:

ViewController:

extension ViewController: TableViewCellDelegate {
    func tableView(shouldExpand cell: TableViewCell) {
        tableView.performBatchUpdates({
            cell.expand()
        })
    }

    func tableView(shouldCollapse cell: TableViewCell) {
        tableView.performBatchUpdates({
            cell.collapse()
        })
    }
}

TableViewCell:

func expand() {
    UIView.animate(withDuration: 0.57) {
        self.viewHeight.constant = 320
        self.view.alpha = 1
        self.layoutIfNeeded()
    }
}

func collapse() {
    UIView.animate(withDuration: 0.57) {
        self.viewHeight.constant = 0
        self.view.alpha = 0
        self.layoutIfNeeded()
    }
}

如何停止上视图停止调整大小?

ios swift uitableview autolayout
1个回答
0
投票

performBatchUpdates用于根据数据源中的更改为tableView中的更改制作动画。由于您在数据源中没有任何更改,因此无需在tableView.performBatchUpdates块内进行动画处理。不使用performBatchUpdates即可尝试。

func tableView(shouldExpand cell: TableViewCell) {
     cell.expand()
}

func tableView(shouldCollapse cell: TableViewCell) {
     cell.collapse()
}
© www.soinside.com 2019 - 2024. All rights reserved.