Added activate/deactivate

This commit is contained in:
Robert Payne 2015-04-11 21:44:46 +12:00
parent ded4778181
commit 3c3a76cf6e
1 changed files with 22 additions and 0 deletions

View File

@ -291,6 +291,28 @@ final public class Constraint {
self.uninstallFromView() self.uninstallFromView()
} }
public func activate() {
if NSLayoutConstraint.respondsToSelector("activateConstraints:") && self.installInfo != nil {
let layoutConstraints = self.installInfo!.layoutConstraints.allObjects as! [LayoutConstraint]
if layoutConstraints.count > 0 {
NSLayoutConstraint.activateConstraints(layoutConstraints)
}
} else {
self.install()
}
}
public func deactivate() {
if NSLayoutConstraint.respondsToSelector("deactivateConstraints:") && self.installInfo != nil {
let layoutConstraints = self.installInfo!.layoutConstraints.allObjects as! [LayoutConstraint]
if layoutConstraints.count > 0 {
NSLayoutConstraint.deactivateConstraints(layoutConstraints)
}
} else {
self.uninstall()
}
}
// MARK: internal // MARK: internal
internal func installOnView(updateExisting: Bool = false) -> [LayoutConstraint] { internal func installOnView(updateExisting: Bool = false) -> [LayoutConstraint] {