Reputation: 33
I have a stackview whose height is 250. I want to program:
How can I get it to go to the top of the screen & then reset it to its original height? The stack I want to go upto the top of the superview
Upvotes: 0
Views: 178
Reputation: 10112
stackViewHeightConstraint
has a priority of 999
.stackView.topAnchor equalTo superview.topAnchor
(DO NOT ACTIVATE IT).top-to-top
constraint.top-to-top
constraint.class ViewController: UIViewController {
@IBOutlet var stackView: UIStackView!
// Assumes that stackView is added as a subview in self.view
private lazy var topToTopConstraint: NSLayoutConstraint = {
stackView.topAnchor.constraint(equalTo: self.view.topAnchor)
}()
@IBAction func expand() {
NSLayoutConstraint.activate([topToTopConstraint])
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { [weak self] in
guard let self = self else { return }
NSLayoutConstraint.deactivate([self.topToTopConstraint])
}
}
}
Upvotes: 2