The code listed below has a button that when is pressed makes the large blue box turn into a small blue box. How can the code be written so that I can just click on the blue box for it turn into the smaller box? The blue boxes are not images they are simply are coded using uicolorview. Thanks
class ViewController: UIViewController {
let colorview = UIView()
var allc = [NSLayoutConstraint]()
override func viewDidLoad() {
super.viewDidLoad()
colorview.translatesAutoresizingMaskIntoConstraints = false
colorview.backgroundColor = UIColor.blueColor()
self.view.addSubview((colorview))
let leadingc = colorview.leadingAnchor.constraintEqualToAnchor(self.view.leadingAnchor)
let trailingC = colorview.trailingAnchor.constraintEqualToAnchor(self.view.trailingAnchor)
let topc = colorview.topAnchor.constraintEqualToAnchor(self.view.topAnchor)
let bottomc = colorview.bottomAnchor.constraintEqualToAnchor(self.view.bottomAnchor, constant: -50)
NSLayoutConstraint.activateConstraints([leadingc, trailingC, topc, bottomc])
let widthc = colorview.widthAnchor.constraintEqualToConstant(100)
let heightc = colorview.heightAnchor.constraintEqualToConstant(100)
let centerxc = colorview.centerXAnchor.constraintEqualToAnchor(self.view.centerXAnchor)
let centeryc = colorview.centerYAnchor.constraintEqualToAnchor(self.view.centerYAnchor)
allc = [leadingc, trailingC, topc, bottomc, widthc, heightc, centerxc, centeryc]
}
@IBAction func changethebleep(sender: AnyObject) {
var newactive = [NSLayoutConstraint]()
for constraint in allc {
if constraint.active {
constraint.active = false
} else {
newactive.append(constraint)
}
}
NSLayoutConstraint.activateConstraints(newactive)
}
}