Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.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
Ios UITableViewCell高度动画和内容_Ios_Swift_Uitableview_Cocoa Touch_Uiviewanimation - Fatal编程技术网

Ios UITableViewCell高度动画和内容

Ios UITableViewCell高度动画和内容,ios,swift,uitableview,cocoa-touch,uiviewanimation,Ios,Swift,Uitableview,Cocoa Touch,Uiviewanimation,我已经搜索了Stack Overflow和其他源代码,但尽管有类似的问题标题,我还是找不到解决方案 我想做的是将UITableViewCellheight与内容一起制作动画。以下是一个例子: 细胞的中央有一块蓝色的嵌板。我希望这个面板的高度与单元格本身一起设置动画 我试过两种方法: 首先:如上图所示更改行高和设置约束: override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

我已经搜索了Stack Overflow和其他源代码,但尽管有类似的问题标题,我还是找不到解决方案

我想做的是将
UITableViewCell
height
与内容一起制作动画。以下是一个例子:

细胞的中央有一块蓝色的嵌板。我希望这个面板的高度与单元格本身一起设置动画

我试过两种方法:

首先:如上图所示更改行高和设置约束:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    tableView.beginUpdates()
    tableView.endUpdates()
}

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    let selectedIndexPath = tableView.indexPathForSelectedRow
    return indexPath == selectedIndexPath ? 120.0 : 70.0
}
Second:将行的高度设置为
UITableViewAutomaticDimension
,将高度约束添加到蓝色区域,并在用户点击单元格时更改此约束。

这两种方法都会立即更改蓝色区域的高度,然后设置单元格高度的动画。我需要蓝色区域与单元格高度一起平滑地设置动画,所以单元格之间的白色间距不变


您试过这个吗?是的,它不工作,我将添加到测试项目的链接