约束动画需要view调用一下layoutIfNeeded才可以, 直接上代码
// MARK: - 弹簧动画
private func settingAnimation() {
// 更新约束
self.iconImageView.snp_updateConstraints(closure: { (make) -> Void in
make.bottom.equalTo(self.view.snp_bottom).offset(-UIScreen.mainScreen().bounds.height + 200)
})
// usingSpringWithDamping: 弹簧效果 0~1.0 取值越小,弹簧效果越明显
// initialSpringVelocity:表示初始的速度
// OC里给枚举的默认值是 填写 0;swift中 用 []标示
UIView.animateWithDuration(1.5, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 10, options: [], animations: { () -> Void in
// 约束动画,需要调用layoutIfNeeded
self.view.layoutIfNeeded()
}) { (_) -> Void in
printLog("动画完成")
// MARK: - 切换控制器视图
NSNotificationCenter.defaultCenter().postNotificationName(kNotificationChangeViewController, object: self)
}
}
约束一定要在动画之前, 在动画中调用一下layoutIfNeeded, 要不然不会达到你想要的效果的