加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

uitableview – 没有行动画动画的ReloadRowsAtIndexPaths

发布时间:2020-12-14 05:22:53 所属栏目:百科 来源:网络整理
导读:这段代码的问题(在func tableView中(tableView:UITableView,commitEditingStyle editingStyle:UITableViewCellEditingStyle,forRowAtIndexPath indexPath:NSIndexPath)) tableView.deleteRowsAtIndexPaths([indexPath],withRowAnimation: .Automatic)if i
这段代码的问题(在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()也不是一个坏主意.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读