ios - Swift 动画 UITableViewCell 扩展高度约束

标签 ios swift animation tableview constraints

<分区>

我有一个 TableView,里面有一个static cell,我想在按下按钮时展开它。单元格内有一个容器 View 约束 已正确设置,但我不确定如何为单元格扩展设置动画,因为它需要我刷新 < strong> TableView 更新约束并展开单元格。

目前,当我调用 expandContainerView 时,它没有动画,因为我正在调用 self.tableView.reloadData

这是我用来展开单元格的代码

@objc private func expandContainerView(notification: NSNotification) {

    self.view.layoutIfNeeded()

    UIView.animate(withDuration: 2.0, delay: 0.0, options: .curveEaseOut, animations: {
        self.containerHeightConstraint.constant = 410
        self.view.layoutIfNeeded()
        self.tableView.reloadData()
    }, completion: nil)
}

这是我在索引代码处每一行的高度

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

    return UITableViewAutomaticDimension
}

最佳答案

尝试不使用动画 block :

containerHeightConstraint.constant = 410
tableView.beginUpdates()
tableView.endUpdates()

关于ios - Swift 动画 UITableViewCell 扩展高度约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48854761/

相关文章:

ios - 字典不允许我将字符串附加到它的值

ios - 防止我的应用程序在后台模式下暂停?

ios - didSelectRowAt Swift 3 即使在设置了委托(delegate)和数据源后也未调用

ios - 从 ContainerView 委托(delegate)给父 ViewController

javascript - 像蜗牛一样在路径上进行 SVG 动画

android - 在android中显示和隐藏 View 动画

ios - 如何快速停止动画返回?

ios - 有没有办法在 Swift 中将 UIPickerView 添加到 UIAlertController(Alert 或 ActionSheet)中?

ios - UIStatusBar 作为 Facebook 新的 iOS7 应用程序

ios - 使用函数式 Swift 搜索 UIView 层次结构