ios - 关于单元格高度更新问题的静态 UITableViewCell 动画中的 UIPickerView
问题描述
我有一个静态UITableView
,其中我有UIPickerView
一个UITableViewCell
. 触发didSelectRowAt
时,它应该切换具有UIPickerView
. 我使用beginUpdates()
andendUpdates()
来改变单元格的高度。它在展开时看起来正确,但在折叠时,UIPickerView
它没有动画并且比单元格更快地折叠。不知道我做错了什么。
我已确保所有视图都设置true
为clipToBounds
、UITableViewCell
ContentView (的UITableViewCell
)和UIPickerView
. 我试图将 beginUpdates/endUpdates 包装在DispatchQueue.main.async
. 我UIPickerView
正在使用 AutoLayout 并且(前导、尾随、顶部、底部)边缘等于单元格的内容视图。我正在为我的 UI 使用 StoryBoard。
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch (indexPath.section, indexPath.row) {
case (1,1):
showPicker = !showPicker
tableView.beginUpdates()
tableView.endUpdates()
default:
()
}
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
switch (indexPath.section, indexPath.row) {
case (1, 1):
if !showDueDate {
return 0
}
case (1, 2):
if !showPicker {
return 0
}
case (_, _):
break
}
return super.tableView(tableView, heightForRowAt: indexPath)
}
我希望动画流畅并UIPickerView
与UITabeViewCell
.
查看 gif 以查看问题
解决方案
使用self.tableView.reloadRows(at: IndexPath(row: indexPath.row, section: indexPath.section), with: .fade)
代替beginUpdates
/ endUpdates
。当动画表更改时,它将为您提供流畅的动画。
推荐阅读
- android - Android - 从 Firebase 数据库中删除“活动”标记
- java - 如何在 Eclipse 中调试 sun.net 内部类?
- java - Junit5 错误。您必须为此 @ParameterizedTest 提供至少一个参数
- javascript - iOS 上的缩放控件不再可见
- django - 如何在 Django 中管理快速增长的 postgres 表?
- encryption - Travis 使用 openssl 解密加密文件失败
- javascript - 如何设置来自 API 的 JSON 数据计数以允许列表中的那么多?
- node.js - 防止 express 中间件为相同的父路径执行
- c# - 如何从本地文件播放音乐
- android - TextView 中的偏移文本