我在视图控制器中有一个容器视图,其中包含一个按钮,每次按下该按钮都会在父视图控制器中向下移动标签。我通过准备segue将标签的约束传递给容器。从那里我可以修改约束,但它不会动画。
我该怎么做?
class ViewController: UIViewController {
@IBOutlet weak var LabelTopConstraint: NSLayoutConstraint!
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "containerSegue" {
let container = segue.destination as? Container
container?.LabelTopConstraint = LabelTopConstraint
}
}
}
class Container: UIViewController {
weak var LabelTopConstraint: NSLayoutConstraint!
@IBAction func MoveLabelButtonPressed(_ sender: Any) {
LabelTopConstraint.constant += 30
UIView.animate(withDuration: 0.35, animations: {
self.view.layoutIfNeeded()
})
}
}
答案 0 :(得分:1)