我正在尝试了解 iOS 中的动画
如果我想改变 View 的 heightConstraint 我设置这样的代码
@objc func handleAnimatioButtonTapped(){
targetViewHeightConstraint.constant = 200
UIView.animated(2) {
self.view.layoutIfNeeded()
}
}
我读到了关于 layoutIfNeeded()
和 setNeedsLayout
、异步和同步
但是当我想改变alpha时
为什么代码是这样的?
@objc func handleAnimatioButtonTapped(){
UIView.animated(2) {
self.targetView.alpha = 0
}
}
最佳答案
您不需要调用layoutIfNeeded()或任何其他函数,因为您没有更新任何东西的布局/位置,只是更新 View 的alpha值。
关于ios - 为什么动画 block 中的 alpha 和约束常量位置不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49715452/