这段代码的问题(在 func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) 内)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
if indexPath.row > 1{
tableView.reloadRowsAtIndexPaths([NSIndexPath(forRow: indexPath.row-1, inSection: 0)], withRowAnimation: .None)
}
if tDate[activeRow].count == 0{
tableView.reloadRowsAtIndexPaths([NSIndexPath(forRow: 0, inSection: 0)], withRowAnimation: .None)
}
虽然指定了 withRowAnimation: .None ,但是 reloadRowsAtIndexPaths 都是动画的 . 我在这里想念的是什么?
2 回答
在
iOS
和OS X
中通常会出现这样或那样的隐式动画(例如,代码正由其他已触发动画的代码执行) .根据我的经验,用
UITableView
和UICollectionView
控制动画可能特别困难 . 你最好的选择可能是将reloadRowsAtIndexPaths:withRowAnimation:
的调用放入一个传递给UIView
的performWithoutAnimations:
方法的闭包中:注意:在多次更新同时发生之前和之后调用
tableView.beginUpdates()
和tableView.endUpdates()
也不是一个坏主意 .虽然查尔斯描述了这个问题的适当解决方案,但它没有回答为什么
UITableViewRowAnimation.none
提供动画的问题 .根据
UITableViewRowAnimation.none
的文档,"The inserted or deleted rows use the default animations."因此,虽然.none
听起来不应该有动画,但它实际上更像是.automatic
.我会留下这个评论,但评论不能包含图片 . 请注意,这个答案并不是为了解决问题,因为Charles已经这样做了 . 这仅供下一个想知道为什么
UITableViewRowAnimation.none
提供动画的人参考 .