gpt4 book ai didi

ios - 如何在 Swift 的 tableView 上添加动画

转载 作者:行者123 更新时间:2023-11-30 12:52:31 27 4
gpt4 key购买 nike

我想在UITableView加载单元格时添加动画(从上到下)但是对此一无所知,请有人帮助我。

下面添加了一个带有数组(arrHeader)的简单 TableView 委托(delegate)方法。

提前致谢

let arrHeader = ["City1", "City2", "City3"]


func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arrHeader.count
}


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCellWithIdentifier("cell")
cell?.textLabel?.text = arrSubHeader[indexPath.row]

return cell!
}

最佳答案

将动画代码放入此 UItableView 委托(delegate)方法中:

override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
//TODO: animation code

}

每次在 iPhone/iPad 屏幕上显示新的或旧的单元格时,都会调用此委托(delegate)方法。

因此,如果您在该 block 中尝试使用单元格执行某些操作,它会反射(reflect)在单元格上。

optional func tableView(_ tableView: UITableView, 
didEndDisplaying cell: UITableViewCell,
forRowAt indexPath: IndexPath) { }

显示单元格后调用此方法。

这是示例的 github 链接:

访问:https://github.com/subhajitregor/TableCellCardDropAnimationExample

关于ios - 如何在 Swift 的 tableView 上添加动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40793560/

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