【问题标题】:Swift: Animate expanding rows in a UITableView?Swift:在 UITableView 中动画扩展行?
【发布时间】:2016-07-24 11:33:29
【问题描述】:

我目前有一个 UITableView,其中一行返回 0.0,然后在用户点击“显示更多”按钮时展开。发生这种情况时,上面的行会根据容器的高度返回一个特定的值,这会立即发生。我想做的是在扩展/减少的同时创建某种动画。

这是我目前的代码:

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

    if indexPath.row == 2 && self.numberOfElements >= 2 {
        if detailsVisible == false {
            self.showMoreLabel.text = "Show more (\(self.numberOfElements - 1))"
            return 0.0
        }
        else {
            self.showMoreLabel.text = "Show less"
            return embedKonteringHeight
        }
    }
}

如果显示可扩展内容,var detailsVisible返回布尔值。

有没有一种简单的动画方法?我在想像一个简单的计数器增加/减少,它由 heightForRowAtIndexPath 在间隔内返回。

【问题讨论】:

    标签: swift xcode uitableview jquery-animate heightforrowatindexpath


    【解决方案1】:

    好的,经过一番研究,我发现了一种非常有效的方法。我会在这里发布,以防有​​人想知道答案。

    在didSelectRowAtIndexPath中,我只需要替换

    tableView.reloadData()
    

    与

    tableView.beginUpdates()
    tableView.endUpdates()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-14
      • 2016-05-20
      • 1970-01-01
      • 2017-12-28
      • 1970-01-01
      • 1970-01-01
      • 2017-11-09
      相关资源
      最近更新 更多