【发布时间】:2018-05-23 00:54:47
【问题描述】:
我有带有静态单元格的 UITableView。我已将相等的内容视图高度约束设置为等于 UIPicker 视图高度。我还通过更改 UITableViewCell 内容视图实现了 didSelectRowAt 方法。 https://youtu.be/lJuTLQ1oTaE
魔术发生了,改变 TableViewCell 的高度是动画的。但是 UIPickerView 高度的以下变化同时发生,没有动画。我曾尝试将 UIView.animate 与 layoutIfNeeded() 一起使用,但没有帮助。
如何为 UIPickerView 高度的这种自动变化设置动画?
// TableView functions
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let cell = tableView.cellForRow(at: indexPath) {
let reuseIdentifier = cell.reuseIdentifier
guard reuseIdentifier != nil else {return}
if reuseIdentifier == "currencyPickerTableViewCell" && self.selectedCellIndexPath == nil {
self.skipCellsFromGestureRecognition.append(indexPath)
self.selectedCellIndexPath = indexPath
print(currencyPicker.constraints)
tableView.beginUpdates()
tableView.endUpdates()
} else if reuseIdentifier == "currencyPickerTableViewCell" && self.selectedCellIndexPath != nil {
self.selectedCellIndexPath = nil
self.tableView.beginUpdates()
self.tableView.endUpdates()
}
}
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if self.selectedCellIndexPath == indexPath {
return self.selectedCellHeight
} else {
return self.unselectedCellHeight
}
}
【问题讨论】:
标签: ios swift uipickerview