Han*_*ber 10 uitableview xcode7 swift2
这段代码的问题(在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)
}
Run Code Online (Sandbox Code Playgroud)
是两个reloadRowsAtIndexPaths动画,虽然withRowAnimation:.None被指定.我在这里错过了什么?
Cha*_* A. 17
通常情况是这样,iOS并且OS X由于某种原因最终导致隐式动画(例如,代码正由其他已触发动画的代码执行).
它可以是特别难以控制动画UITableView,并UICollectionView在我的经验.最好的办法可能是把调用reloadRowsAtIndexPaths:withRowAnimation:到传递给关闭UIView的performWithoutAnimations:方法:
UIView.performWithoutAnimation {
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)
}
}
Run Code Online (Sandbox Code Playgroud)
注:这也是个不错的主意,打电话tableView.beginUpdates()和tableView.endUpdates()之前那一次全部发生多次更新后.
虽然查尔斯描述了这个问题的适当解决方案,但它没有回答为什么UITableViewRowAnimation.none提供动画的问题.
根据文档UITableViewRowAnimation.none,"插入或删除的行使用默认动画".因此,虽然.none声音不应该是动画,但它实际上更像是动画.automatic.
我会留下这个评论,但评论不能包含图片.请注意,这个答案并不是为了解决问题,因为Charles已经这样做了.这仅供下一个想知道为什么UITableViewRowAnimation.none提供动画的人参考.
| 归档时间: |
|
| 查看次数: |
4583 次 |
| 最近记录: |