uitableview – 没有行动画动画的ReloadRowsAtIndexPaths

这段代码的问题(在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,withRowAnimation: .None)
}

是两个reloadRowsAtIndexPaths动画,虽然withRowAnimation:.None被指定.我在这里错过了什么?

在iOS和OS X中通常会出现这样或那样的隐式动画(例如,代码正由其他已经触发动画的代码执行).

根据我的经验,使用UITableView和UICollectionView控制动画可能特别困难.你最好的选择可能是调用reloadRowsAtIndexPaths:withRowAnimation:进入一个传递给UIView的performWithoutAnimations:方法的闭包:

UIView.performWithoutAnimation {
    if indexPath.row > 1{
        tableView.reloadRowsAtIndexPaths([NSIndexPath(forRow: indexPath.row-1,withRowAnimation: .None)
    }
    if tDate[activeRow].count == 0{
        tableView.reloadRowsAtIndexPaths([NSIndexPath(forRow: 0,withRowAnimation: .None)
    }
}

注意:在一次发生多个更新之前和之后调用tableView.beginUpdates()和tableView.endUpdates()也不是一个坏主意.

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...