用Swiftanimation视图高度
我有我的ViewController中查看sView 。 它的高度有约束 – 我为这个约束创build了IBOutlet – sViewHeightConstraint 。 我想用animation降低sView的高度。
我创build了函数
UIView.animateWithDuration(5.5, animations: { self.sViewHeightConstraint.constant = 50 })
视图高度正在改变,但我没有看到任何animation。 我做错了什么?
使用layoutIfNeeded()
view.layoutIfNeeded() // force any pending operations to finish UIView.animateWithDuration(0.2, animations: { () -> Void in self.sViewHeightConstraint.constant = 50 self.view.layoutIfNeeded() })
迅速3
view.layoutIfNeeded() sViewHeightConstraint.constant = 50 UIView.animate(withDuration: 1.0, animations: { self.view.layoutIfNeeded() })