From 3c3a76cf6eec62b579865b34c2262c4bdf387ef6 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Sat, 11 Apr 2015 21:44:46 +1200 Subject: [PATCH] Added activate/deactivate --- Source/Constraint.swift | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Source/Constraint.swift b/Source/Constraint.swift index 34b44a6..020aec2 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -291,6 +291,28 @@ final public class Constraint { 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 internal func installOnView(updateExisting: Bool = false) -> [LayoutConstraint] {