使用Swift

时间:2016-04-30 10:06:49

标签: ios xcode swift autolayout

我在ViewController中查看 sView 。它的高度有约束 - 我为这个约束创建了IBOutlet - sViewHeightConstraint 。我想用动画减少sView的高度。

我创建了函数

UIView.animateWithDuration(5.5, animations: {
                self.sViewHeightConstraint.constant = 50
            })

视野的高度正在改变,但我看不到任何动画。我做错了什么?

1 个答案:

答案 0 :(得分:47)

使用git cherry-pick -n

layoutIfNeeded()

swift 3

 view.layoutIfNeeded() // force any pending operations to finish

 UIView.animateWithDuration(0.2, animations: { () -> Void in
    self.sViewHeightConstraint.constant = 50
    self.view.layoutIfNeeded()
})
相关问题