UITableView插入动画无法正常显示(?)

时间:2015-04-23 23:09:08

标签: ios uitableview swift animation uikit

我正在努力获得我想要的插入动画,至少应该发生的事情没有发生,我看不出我做错了什么。 使用.Bottom和.Top UITableViewRowAnimations与insertRowsAtIndexPaths:withRowAnimation:不产生我期望的动画。它们似乎都会影响我指定的单元格之上或之下的单元格。

任何人都可以解释为什么(我可能会弄错)?

以下是所有相关代码:

@IBAction func add(sender: UIBarButtonItem) {
    model.pots.insert(Pot(name: "test", initial: 0, creationDate: NSDate(), startDate: NSDate(), expenditure: [], regularTopUps: [], extraTopUps: []), atIndex: 1)
    tableView.insertRowsAtIndexPaths([NSIndexPath(forItem: 1, inSection: 0)], withRowAnimation: UITableViewRowAnimation.Bottom)
}

因此,例如在这个例子中,我希望新细胞从细胞0下方滑入并向下推细胞1-2并取细胞1位置。实际发生的是新单元瞬间占据1个位置然后先前的单元1-2向下滑动,旧单元1从新单元下方进入。 有趣的是,如果我改为使用

@IBAction func add(sender: UIBarButtonItem) {
    model.pots.insert(Pot(name: "test", initial: 0, creationDate: NSDate(), startDate: NSDate(), expenditure: [], regularTopUps: [], extraTopUps: []), atIndex: 1)
    tableView.insertRowsAtIndexPaths([NSIndexPath(forItem: 0, inSection: 0)], withRowAnimation: UITableViewRowAnimation.Bottom)
}

我大致得到了我期望的行为。 我对.Top动画有类似的问题,但我认为我没有其他任何一个。

非常感谢。

0 个答案:

没有答案
相关问题