微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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()也不是一个坏主意.

原文地址:https://www.jb51.cc/swift/319000.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐