/// 设置视图子控件的约束
private func setSubViewsLayout(){
// 添加视图
view.addSubview(iocnView)
view.addSubview(nameLable)
// 要先设置头像的约束
iocnView.snp_makeConstraints { (make) -> Void in
make.centerX.equalTo(view.snp_centerX)
make.bottom.equalTo(view.snp_bottom).offset(-200)
}
nameLable.snp_makeConstraints { (make) -> Void in
// 宽高不用去设置了
make.centerX.equalTo(view.snp_centerX)
make.top.equalTo(iocnView.snp_bottom).offset(20)
}
}
func setAnmiation(){
// 如何怎么修改约束..
// 更新一下头像的地步约束
//咱们这个动画是通过修改头像的约束才可以进行的.. 因为名称lable是依赖他的
iocnView.snp_updateConstraints { (make) -> Void in
//make.centerX.equalTo(view.snp_centerX)
make.bottom.equalTo(view.snp_bottom).offset(-UIScreen.mainScreen().bounds.height+150)
}
//
// UIView.animateWithDuration(2, animations: { () -> Void in
//
// // 这是普通的动画效果
// })
// 弹簧动画效果
/*
1. 动画执行几秒
2. 延迟时间
3 usingSpringWithDamping 弹簧浮动系数 0~1;系数越大,弹簧效果越明显
4 initialSpringVelocity: 弹簧的初始速度
5.枚举: OC默认用 0,swift 默认用 []
*/
UIView.animateWithDuration(2, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
//动画执行代码
self.view.layoutIfNeeded()
}, completion: { (_) -> Void in
//动画执行完成之后的操作
NSNotificationCenter.defaultCenter().postNotificationName(kNotificationChangeController, object: self)
})
}
layoutIfNeeded: 这个就关键