I keep references to my NSLayoutConstraint
var flag = true
@IBOutlet weak var myConstraint: NSLayoutConstraint!
Then for some @IBAction
I activate/deactivate depending on my flag
variable:
@IBAction func tapped(sender: UIButton) {
flag = !flag
UIView.animateWithDuration(1.0) {
if self.flag {
NSLayoutConstraint.activateConstraints([self. myConstraint])
} else {
NSLayoutConstraint.deactivateConstraints([self. myConstraint])
}
}
}
But when I call my action once again, I have an error unexpectedly found nil while unwrapping an Optional value
for myConstrain
.
More over it doesn't animate. What am I doing wrong?
I follow tutorial from WWDC 2015: