我在 Interface Builder 中只使用了 NSConstraints 来设置 View 。现在我有一个要制作动画的 StackView。这会导致所有布局错位。
- 我曾尝试用临时 View (具有相同的框架)替换 View (StackView),但这没有用。
我还尝试设置
translatesAutoresizingMaskIntoConstraints
还尝试了以下方法:
self.numbers_Top_Constraint.constant = self.topscreen.frame.size.height self.topscreen.setNeedsUpdateConstraints() UIView.animate(withDuration: 0.5, animations: { self.topscreen.layoutIfNeeded()
你知道怎么做吗?
最佳答案
使用约束而不是更改框架。 设置堆栈 View 的顶部边距约束,然后在动画之前更改它并调用 self.view.layoutIfNeeded()。 像这样的东西 -
self.numbersStackViewTopMarginConstriant.constant = self.view.frame.size.height
UIView.animate(withDuration: 0.5, animations: {
self.view.layoutIfNeeded()
}) { (Bool) in
关于ios - 替换 Autolayout NSConstraints 设置中的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44455598/