【问题标题】:Animating collection view height change (Swift)动画集合视图高度变化(Swift)
【发布时间】:2016-05-15 20:47:13
【问题描述】:

我正在尝试为集合视图设置高度变化的动画,但我不知道如何使动画工作。高度会正确更改,但会立即发生,而不是动画。

@IBOutlet weak var collectionViewHeight: NSLayoutConstraint!

UIView.animateWithDuration(0.3, delay: 0, options: .CurveEaseOut, animations: {
            self.collectionViewHeight.constant = 0
            }

我尝试搜索解决方案,但找不到特定于这种情况的任何东西。还尝试了这里建议的layoutIfNeeded(),但没有帮助:Animate view height with Swift

非常感谢任何帮助!

【问题讨论】:

    标签: ios swift uicollectionview


    【解决方案1】:

    您应该在动画块之外更新约束的常量:

    self.collectionViewHeight.constant = 0
    UIView.animateWithDuration(0.3, delay: 0, options: .CurveEaseOut,   
      animations: view.layoutIfNeeded, completion: nil)
    

    view 是相关集合视图的父视图。)

    【讨论】:

    • 谢谢!!这行得通! (... self.view.layoutIfNeeded() ...)
    猜你喜欢
    • 1970-01-01
    • 2016-08-25
    • 1970-01-01
    • 2021-12-29
    • 2022-01-19
    • 2015-02-27
    • 1970-01-01
    • 2018-09-13
    • 1970-01-01
    相关资源
    最近更新 更多