我有带有静态单元格的 UITableView。我已设置相等的内容 View 高度约束等于 UIPicker View 高度。我还通过更改 UITableViewCell 内容 View 实现了 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
}
}
最佳答案
动画确实发生了,但由于 UIPicker 的字体保持不变,你看不到它,因此更改 UIView.animate 内的字体,另请注意选择器的宽度是静态的,因此,随着字体变大,修剪的字符数量将会增加。 。 。
关于iOS Animate UIPicker 高度变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47720094/