gpt4 book ai didi

ios - 单元格在 UITableView 动画期间消失

转载 作者:可可西里 更新时间:2023-11-01 03:58:47 26 4
gpt4 key购买 nike

我的 UIViewController 中有一个普通的 UITableView,限制为全屏。这个 tableView 有一个自定义的交互式 tableHeaderView。 tableHeaderView 的大小是动态的,并且会自行扩展。headerView 有一个 textField,并且会根据 textField 是否有焦点来改变自己的大小。

问题在于,当更改 tableHeaderView 的大小时,屏幕底部的单元格并不总是正确地设置动画。我在动画 block 中的 layoutIfNeeded() 之后调用 tableView.beginUpdates()tableView.endUpdates()。必须这样做,否则单元格根本不会遵循动态大小。

我制作了这个 gif。在动画过程中特别注意底部的单元格。我大大放慢了动画速度,因此很容易看出问题所在。

gif of problem

推测:在我看来,一旦动画开始,tableView 就会调用 cellForRow:indexPath:,并以某种方式找出整个 tableView 在动画之后将处于什么状态,然后删除不必要的单元格,即使动画尚未完成。同样,当折叠标题时:最底部的单元格不会以与已加载的单元格相同的方式进行动画处理。他们用不同的动画动画..

为什么会这样?这是可以预防的吗?

编辑:动画代码

self.navigationController?.setNavigationBarHidden(isEditing, animated: true)

var frame = tableHeaderView.frame
frame.size.height = tableHeaderView.headerHeight(forEditing: isEditing)

UIView.animate(withDuration: 0.3, animations: {

if isEditing{
let point = CGPoint(x: 0, y: -self.topLayoutGuide.length)
self.tableView.setContentOffset(point, animated: false)
}

tableHeaderView.frame = frame
tableHeaderView.layoutIfNeeded()
self.view.layoutIfNeeded()
self.tableView.beginUpdates()
self.tableView.endUpdates()
}) { [weak self](completed:Bool) in
//Do stuff
}

最佳答案

我刚刚收到 Apple 开发人员技术支持团队关于此问题的回复,以下是他们的逐字回复(强调我的):

Hello Nicolas,

Thank you for contacting Apple Developer Technical Support (DTS).

The behavior and resulting limitations you describe are by design.

If you believe an alternative approach should be considered by Apple, we encourage you to file an enhancement request with information on how this design decision impacts you, and what you’d like to see done differently.

Although there is no promise that the behavior will be changed, it is the best way to ensure your thoughts on the matter are seen by the team responsible for the decision.

Best Regards,

Apple Developer Technical Support

看来我们只是不得不使用对 tableView.setContentOffset(_:animated:)tableView.scrollToRow(at:at:animated:) 的简单调用

关于ios - 单元格在 UITableView 动画期间消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41933077/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com