为什么我的列表删除动画在 Swift 中不起作用



我在下面的视图控制器子类中有一个函数,它应该在2.5秒内动画化列表下降作为测试,但它会立即将列表

private func animateList() {

if listDropped == false {
UIView.animate(withDuration: 2.5, delay: 0.0, options: .curveEaseInOut) {
self.tableView.isHidden = false
self.listDropped = true
} completion: { (finish) in
print("DEBUG: list drop animation complete")
}
}
else {

UIView.animate(withDuration: 2.5, delay: 0.0, options: .curveEaseInOut) {
self.tableView.isHidden = true
self.listDropped = false
} completion: { (finish) in
print("DEBUG: list raise animation complete")
}
}
}

我试着阅读了文档,但我确信我正确地实现了animate方法。我只是不明白为什么每次我按下下拉列表按钮时,它都没有上下动画列表。

用于使用UIView动画上下显示动画。您应该更新tableView的高度来代替它们的可见性。

请在下面找到示例代码:

private func animateList() {

if listDropped == false {
UIView.animate(withDuration: 2.5, delay: 0.0, options: .curveEaseInOut) {
var rect = self.tableView.frame
rect.size.height = 120(or any value)
self.tableView.frame = rect
self.listDropped = true
} completion: { (finish) in
self.tableView.isHidden = false
print("DEBUG: list drop animation complete")
}
}
else {

UIView.animate(withDuration: 2.5, delay: 0.0, options: .curveEaseInOut) {
var rect = self.tableView.frame
rect.size.height = 0(or any value)
self.tableView.frame = rect
self.listDropped = false
} completion: { (finish) in
self.tableView.isHidden = true
print("DEBUG: list raise animation complete")
}
}
}

最新更新