Browse Source

Merge pull request #17 from cnoon/feature/uninstalling_constraints

Added a method for uninstalling constraints on a view.
Robert Payne 11 years ago
parent
commit
ef24bbeb94
2 changed files with 11 additions and 0 deletions
  1. 7 0
      Snappy/ConstraintMaker.swift
  2. 4 0
      Snappy/View+Snappy.swift

+ 7 - 0
Snappy/ConstraintMaker.swift

@@ -97,4 +97,11 @@ public class ConstraintMaker {
         }
         LayoutConstraint.setLayoutConstraints(layoutConstraints, installedOnView: view)
     }
+    
+    internal class func removeConstraints(view: View) {
+        for existingLayoutConstraint in LayoutConstraint.layoutConstraintsInstalledOnView(view) {
+            existingLayoutConstraint.constraint?.uninstall()
+        }
+        LayoutConstraint.setLayoutConstraints([], installedOnView: view)
+    }
 }

+ 4 - 0
Snappy/View+Snappy.swift

@@ -67,4 +67,8 @@ public extension View {
     public func snp_remakeConstraints(block: (maker: ConstraintMaker) -> ()) {
         ConstraintMaker.remakeConstraints(self, block: block)
     }
+    
+    public func snp_removeConstraints() {
+        ConstraintMaker.removeConstraints(self)
+    }
 }