作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在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/
我是一名优秀的程序员,十分优秀!