[英]iOS Animate UIPicker height change
我有带有静态单元格的UITableView。 我设置了相等的Content View高度约束,等于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
}
}
动画实际上发生了,但是当UIPicker的字体保持不变时,您看不到它,因此请在UIView.animate中更改字体,还要注意,选择器的宽度是静态的,因此,修剪的字符数将随着字体变大。 。 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.