如何正确扩展Swift中UITableView的最后一个UITableViewCell?

时间:2018-04-21 18:12:37

标签: ios swift uitableview uiviewanimation

我有一个带可扩展单元格的UITableView,每个单元格都是一个堆栈的组合,我显示或隐藏了这个堆栈的一些元素,用于扩展或折叠单元格。

以下是具有预期行为的GIF:

enter image description here

这是用于更改单元格大小的代码段:

func expandCel(_ cell: MyCell) {
        if let arrowButton = cell.arrowUpDownButton {
            if arrowButton.isSelected {
                UIView.animate(withDuration: 0.2, animations: {
                cell.stackHides.alpha = 0
            }) { [weak self] (_) in
                arrowButton.isSelected = false
                cell.stackHides.isHidden = true
                cell.isCompressed = true
                self?.tableView.beginUpdates()
                self?.tableView.endUpdates()
            }
        } else {
            cell.stackHides.alpha = 0
            UIView.animate(withDuration: 0.2, animations: {
                arrowButton.isSelected = true
                cell.isCompressed = false
                cell.stackHides.isHidden = false
            }) { [weak self] (_) in
                UIView.animate(withDuration: 0.2, animations: {
                    cell.stackHides.alpha = 1
                    self?.tableView.beginUpdates()
                    self?.tableView.endUpdates()
                })
            }
        }
    }
}

一切似乎都运行良好,但 某些单元格扩展后表格的最后一个单元格到达屏幕底部,会发生意外情况... < / p>

第一次我点按最后一个单元格的按钮进行扩展,它会展开,但会立即崩溃

在第一次扩展尝试之后,当我展开或折叠任何单元格(包括最后一个单元格)时似乎工作但我得到另一个不受欢迎的效果,一个奇怪的滚动

如果我折叠单元格直到屏幕底部的最后一个单元格不再存在,那么该表格效果很好。

以下是另一个GIF,可以更好地解释不良行为

enter image description here

0 个答案:

没有答案