First change the IBOutlet variable to an optional. ie:
from :
@IBOutlet weak var myConstraint : NSLayoutConstraint!
to:
@IBOutlet weak var myConstraint : NSLayoutConstraint?
Now, to make it easier to manage/change from the storyboard in the future, add a new variable (eg myConstraint_DefualtValue) and set this to the value of myConstraint in viewDidLoad
var myConstraint_DefualtValue = CGFloat(0)
override func viewDidLoad() {
super.viewDidLoad()
self.myConstraint_DefualtValue = self.myConstraint.constant
}
I assume it is obvious why you need to set it in viewDidLoad and not somewhere else
Then when you want to deactivate it:
self.myConstraint?.isActive = false
And when you want to reactivate it (assuming you have the view as an outlet(myViewThatHasTheConstraint) and the constraint is a height constraint):
self.myConstraint = self.myViewThatHasTheConstraint.heightAnchor.constraint(equalToConstant: self.myConstraint_DefualtValue);
self.myConstraint?.isActive = true