Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 具有调整单元格大小动画的动态单元格大小_Swift_Uitableview_Swift3_Uiviewanimation - Fatal编程技术网

Swift 具有调整单元格大小动画的动态单元格大小

Swift 具有调整单元格大小动画的动态单元格大小,swift,uitableview,swift3,uiviewanimation,Swift,Uitableview,Swift3,Uiviewanimation,我有一个具有动态单元格高度的表格视图。桌子上方是带按钮的菜单。当我点击菜单按钮时,数据被加载到表中。加载数据时,我希望在单元格中有一个动画,可以更改单元格的高度。我想知道如何才能做到这一点 谢谢你的帮助。Swift 4 在模型中创建一个布尔变量,用于检查单元格是否展开。 如果要将单元格扩展到标签高度,则应将标签约束连接到contentView的各个方向,并在情节提要中将行数设置为0 func tableView(_ tableView: UITableView, didSelectRowAt

我有一个具有动态单元格高度的表格视图。桌子上方是带按钮的菜单。当我点击菜单按钮时,数据被加载到表中。加载数据时,我希望在单元格中有一个动画,可以更改单元格的高度。我想知道如何才能做到这一点


谢谢你的帮助。

Swift 4

在模型中创建一个布尔变量,用于检查单元格是否展开。 如果要将单元格扩展到标签高度,则应将标签约束连接到contentView的各个方向,并在情节提要中将行数设置为0

 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
            details[indexPath.row].cellIsOpen = !details[indexPath.row].cellIsOpen
            detailTableView.reloadData()
            detailTableView.beginUpdates()
            detailTableView.endUpdates()
            detailViewHeightConstraint.constant = CGFloat(detailTableView.contentSize.height) // the height of whole tableView
            UIView.animate(withDuration: 0.3) {
                self.view.layoutIfNeeded()
            }
    }

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
            if details[indexPath.row].cellIsOpen {
                return UITableViewAutomaticDimension // or any number you wish
            } else {
                return 60 // default closed cell height
            }
    }
}
也可以在viewDidLoad()函数中放置这两行:

detailTableView.estimatedRowHeight = 60
detailTableView.rowHeight = UITableViewAutomaticDimension