2016-11-24 130 views
0

我想在加载单元UITableView时添加动画(从顶部到底部)但是不知道这个,请别人帮助我。如何在tableView中添加动画Swift

下面添加了一个简单的表视图委托方法与数组(arrHeader)。

在此先感谢

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! 
} 
+0

你想,当它显示给动画添加到每个单元格?或整个tableView的动画? –

+0

我想添加到整个表 –

+0

为了确保我理解你想要实现什么,动画将适用于它自己的tableview,而不是在每个单元格上,对不对? –

回答

0

把你的动画代码在这个UItableView委托方法:

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

} 

此委托方法被称为一个新的或旧的细胞是怎么回事,以显示每一次iPhone/iPad屏幕。

所以,如果你尝试在这个块中的单元格,它会反映在他们身上。

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

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

这里是GitHub的链接,例如:

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

+0

我已经尝试过,但它只动画了第一个单元格。 –

+0

我确实在目标C中有代码,如果你想要我可以与你分享。 –

+0

确定你可以分享。 –