gpt4 book ai didi

ios - 约束动画不起作用

转载 作者:行者123 更新时间:2023-12-01 16:02:25 24 4
gpt4 key购买 nike

我正在尝试在 2 个约束中设置优先级变化的动画,但我似乎无法让它发挥作用。我的动画代码是这样写的:

        UIView.animate(withDuration: 0.2, animations: {
if self.cardHeaderBottomtoBodyTopConstraint.priority == UILayoutPriorityDefaultHigh {
self.cardHeaderBottomtoBodyTopConstraint.priority = UILayoutPriorityDefaultLow
self.cardHeaderBottomToBodyBottomConstraint.priority = UILayoutPriorityDefaultHigh
} else {
self.cardHeaderBottomtoBodyTopConstraint.priority = UILayoutPriorityDefaultHigh
self.cardHeaderBottomToBodyBottomConstraint.priority = UILayoutPriorityDefaultLow
}

self.flightInformationBodyCard.layoutIfNeeded()
self.flightInformationBodyCard.updateConstraints()
}, completion: nil)

最佳答案

我所要做的就是将 layoutIfNeeded 方法更改为 superview,如下所示:

        if self.cardHeaderBottomtoBodyTopConstraint.priority == UILayoutPriorityDefaultHigh {
self.cardHeaderBottomtoBodyTopConstraint.priority = UILayoutPriorityDefaultLow
self.cardHeaderBottomToBodyBottomConstraint.priority = UILayoutPriorityDefaultHigh
} else {
self.cardHeaderBottomtoBodyTopConstraint.priority = UILayoutPriorityDefaultHigh
self.cardHeaderBottomToBodyBottomConstraint.priority = UILayoutPriorityDefaultLow
}

//self.flightInformationBodyCard.updateConstraints()

UIView.animate(withDuration: 0.2, animations: {

self.flightInformationBodyCard.superview?.layoutIfNeeded()

}, completion: nil)

关于ios - 约束动画不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45424028/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com