UIView.animateKeyFrames
. 这是我的密码:
UIView.animateKeyframes(withDuration: 2.0, delay: 0, options: [.calculationModeCubic], animations: {
UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 1.0/2.0, animations: {
self.titleLabel.alpha = 0.0 // works well
})
self.titleSquareHeightConstraint?.constant = 20 // previously 170
UIView.addKeyframe(withRelativeStartTime: 1.0/2.0, relativeDuration: 1.0/2.0, animations: {
self.titleSquare.layoutIfNeeded() // instantaneously jump to 20
})
}, completion:nil)
标题栏的高度会瞬间从170跳到20。
注意:titleSquare是一个UIView
. 还有,我以前和
UIView.animate
下面的代码工作正常:
self.titleSquareHeightConstraint?.constant = 20
UIView.animate(withDuration: 0.5,
delay: 0,
usingSpringWithDamping: 1,
initialSpringVelocity: 1,
options: .curveEaseIn,
animations: {
self.view.layoutIfNeeded() // Perfectly works
},completion: nil)
我的电脑出了什么问题
UIView.animateKeyframes
谢谢