Ios 使用Swift设置视图高度的动画

Ios 使用Swift设置视图高度的动画,ios,xcode,swift,autolayout,Ios,Xcode,Swift,Autolayout,我的ViewController中有viewsView。它的高度有约束-我为此约束创建了IBOutlet-sViewHeightConstraint。我想通过动画降低sView的高度 我创建了一个函数 UIView.animateWithDuration(5.5, animations: { self.sViewHeightConstraint.constant = 50 }) 视图的高度正在更改,但我看不到任何动画。我做错了什么?使用l

我的ViewController中有viewsView。它的高度有约束-我为此约束创建了IBOutlet-sViewHeightConstraint。我想通过动画降低sView的高度

我创建了一个函数

UIView.animateWithDuration(5.5, animations: {
                self.sViewHeightConstraint.constant = 50
            })
视图的高度正在更改,但我看不到任何动画。我做错了什么?

使用
layoutifneed()

swift 3

view.layoutIfNeeded() 
sViewHeightConstraint.constant = 50

UIView.animate(withDuration: 1.0, animations: { 
     self.view.layoutIfNeeded() 
})

@视图上的moonvader
layoutifneed
强制完成所有挂起的操作,然后在动画块中捕获帧更改。有关详细信息,请参阅。检查
view.layoutIfNeeded() 
sViewHeightConstraint.constant = 50

UIView.animate(withDuration: 1.0, animations: { 
     self.view.layoutIfNeeded() 
})