Ios 替换自动布局NSConstraints设置中的视图

Ios 替换自动布局NSConstraints设置中的视图,ios,Ios,我只使用Interface Builder中的NSConstraints来设置视图。现在我有了一个StackView,我想制作动画。这会导致所有布局都放错位置 我尝试用具有相同帧的temp替换viewStackView,但没有成功。 我还尝试设置translatesAutoresizingMaskIntoConstraints 还尝试了以下方法: self.numbers_Top_Constraint.constant = self.topscreen.frame.size.height sel

我只使用Interface Builder中的NSConstraints来设置视图。现在我有了一个StackView,我想制作动画。这会导致所有布局都放错位置

我尝试用具有相同帧的temp替换viewStackView,但没有成功。 我还尝试设置translatesAutoresizingMaskIntoConstraints

还尝试了以下方法:

self.numbers_Top_Constraint.constant = self.topscreen.frame.size.height
self.topscreen.setNeedsUpdateConstraints()
UIView.animate(withDuration: 0.5, animations: {

    self.topscreen.layoutIfNeeded()
}


你知道怎么做吗?

使用约束而不是更改帧。 将“上边距”约束设置为“堆栈视图”,然后在动画之前对其进行更改,并调用self.view.layoutifneed。 像这样的-

self.numbersStackViewTopMarginConstriant.constant = self.view.frame.size.height
UIView.animate(withDuration: 0.5, animations: {

            self.view.layoutIfNeeded()

        }) { (Bool) in

谢谢,虽然它不起作用-我用您的建议更新了问题。您是以编程方式创建视图的吗?在指定给约束时,还要检查视图高度是否正确