在講解autoalayout動(dòng)畫之前,先搞清楚下面三個(gè)方法的作用
layoutSubviews
這個(gè)方法里對(duì)所有的子控件進(jìn)行布局操作,不能主動(dòng)調(diào)用,需要調(diào)用時(shí)候直接調(diào)用setNeedsLayout就好。layoutifNeeded
強(qiáng)制更新布局,從而產(chǎn)生動(dòng)畫效果setNeedsLayout
標(biāo)記需要重新布局,不立即刷新,layoutSubviews會(huì)被調(diào)用。
@IBOutlet weak var heightConstraint: NSLayoutConstraint!
@IBAction func didClick(_ sender: Any) {
heightConstraint.constant += 100
UIView.animate(withDuration: 1, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 5, options: [.curveLinear], animations: {
self.view.layoutIfNeeded()
}, completion: nil)
}