In viewDidLoad
I declared a constraint and added it to the UIViewController
this way:
var constraintButtonPlay = NSLayoutConstraint (item: buttonPlay,
attribute: NSLayoutAttribute.Bottom,
relatedBy: NSLayoutRelation.Equal,
toItem: self.view,
attribute: NSLayoutAttribute.Bottom,
multiplier: 1,
constant: 500)
self.view.addConstraint(constraintButtonPlay)
When a button is pressed, the constraint should update itself. However, this code doesn't work:
@IBAction func buttonTest(sender: AnyObject) {
var constraintButtonPlay = NSLayoutConstraint (item: buttonPlay,
attribute: NSLayoutAttribute.Bottom,
relatedBy: NSLayoutRelation.Equal,
toItem: self.view,
attribute: NSLayoutAttribute.Bottom,
multiplier: 1,
constant: -500)
}
Now, I realize that declaring the variable another time isn't the ideal solution. So is there a way to declare it once and the call it whenever in the @IBAction
?
Why is the @IBAction
code not updating the constraint?