瀏覽代碼

Merge pull request #151 from aleffert/aleffert/layout-anchors

Add support for the iOS 9 Layout Anchor API.
Robert Payne 10 年之前
父節點
當前提交
99d503af97
共有 1 個文件被更改,包括 24 次插入1 次删除
  1. 24 1
      Source/ConstraintDescription.swift

+ 24 - 1
Source/ConstraintDescription.swift

@@ -95,6 +95,8 @@ public protocol ConstraintDescriptionRelatable: class {
     func equalTo(other: View) -> ConstraintDescriptionEditable
     @available(iOS 7.0, *)
     func equalTo(other: LayoutSupport) -> ConstraintDescriptionEditable
+    @available(iOS 9.0, *)
+    func equalTo(other: NSLayoutAnchor) -> ConstraintDescriptionEditable
     func equalTo(other: Float) -> ConstraintDescriptionEditable
     func equalTo(other: Double) -> ConstraintDescriptionEditable
     func equalTo(other: CGFloat) -> ConstraintDescriptionEditable
@@ -108,6 +110,8 @@ public protocol ConstraintDescriptionRelatable: class {
     func lessThanOrEqualTo(other: View) -> ConstraintDescriptionEditable
     @available(iOS 7.0, *)
     func lessThanOrEqualTo(other: LayoutSupport) -> ConstraintDescriptionEditable
+    @available(iOS 9.0, *)
+    func lessThanOrEqualTo(other: NSLayoutAnchor) -> ConstraintDescriptionEditable
     func lessThanOrEqualTo(other: Float) -> ConstraintDescriptionEditable
     func lessThanOrEqualTo(other: Double) -> ConstraintDescriptionEditable
     func lessThanOrEqualTo(other: CGFloat) -> ConstraintDescriptionEditable
@@ -121,6 +125,8 @@ public protocol ConstraintDescriptionRelatable: class {
     func greaterThanOrEqualTo(other: View) -> ConstraintDescriptionEditable
     @available(iOS 7.0, *)
     func greaterThanOrEqualTo(other: LayoutSupport) -> ConstraintDescriptionEditable
+    @available(iOS 9.0, *)
+    func greaterThanOrEqualTo(other: NSLayoutAnchor) -> ConstraintDescriptionEditable
     func greaterThanOrEqualTo(other: Float) -> ConstraintDescriptionEditable
     func greaterThanOrEqualTo(other: Double) -> ConstraintDescriptionEditable
     func greaterThanOrEqualTo(other: CGFloat) -> ConstraintDescriptionEditable
@@ -224,6 +230,10 @@ internal class ConstraintDescription: ConstraintDescriptionExtendable, Constrain
     internal func equalTo(other: LayoutSupport) -> ConstraintDescriptionEditable {
         return self.constrainTo(other, relation: .Equal)
     }
+    @available(iOS 9.0, *)
+    internal func equalTo(other: NSLayoutAnchor) -> ConstraintDescriptionEditable {
+        return self.constrainTo(other, relation: .Equal)
+    }
     internal func equalTo(other: Float) -> ConstraintDescriptionEditable {
         return self.constrainTo(other, relation: .Equal)
     }
@@ -261,6 +271,10 @@ internal class ConstraintDescription: ConstraintDescriptionExtendable, Constrain
     internal func lessThanOrEqualTo(other: LayoutSupport) -> ConstraintDescriptionEditable {
         return self.constrainTo(other, relation: .LessThanOrEqualTo)
     }
+    @available(iOS 9.0, *)
+    internal func lessThanOrEqualTo(other: NSLayoutAnchor) -> ConstraintDescriptionEditable {
+        return self.constrainTo(other, relation: .LessThanOrEqualTo)
+    }
     internal func lessThanOrEqualTo(other: Float) -> ConstraintDescriptionEditable {
         return self.constrainTo(other, relation: .LessThanOrEqualTo)
     }
@@ -298,6 +312,10 @@ internal class ConstraintDescription: ConstraintDescriptionExtendable, Constrain
     internal func greaterThanOrEqualTo(other: LayoutSupport) -> ConstraintDescriptionEditable {
         return self.constrainTo(other, relation: .GreaterThanOrEqualTo)
     }
+    @available(iOS 9.0, *)
+    internal func greaterThanOrEqualTo(other: NSLayoutAnchor) -> ConstraintDescriptionEditable {
+        return self.constrainTo(other, relation: .LessThanOrEqualTo)
+    }
     internal func greaterThanOrEqualTo(other: Float) -> ConstraintDescriptionEditable {
         return self.constrainTo(other, relation: .GreaterThanOrEqualTo)
     }
@@ -547,6 +565,11 @@ internal class ConstraintDescription: ConstraintDescriptionExtendable, Constrain
         return constrainTo(ConstraintItem(object: other, attributes: ConstraintAttributes.None), relation: relation)
     }
     
+    @available(iOS 9.0, *)
+    private func constrainTo(other: NSLayoutAnchor, relation: ConstraintRelation) -> ConstraintDescription {
+        return constrainTo(ConstraintItem(object: other, attributes: ConstraintAttributes.None), relation: relation)
+    }
+    
     private func constrainTo(other: Float, relation: ConstraintRelation) -> ConstraintDescription {
         self.constant = other
         return constrainTo(ConstraintItem(object: nil, attributes: ConstraintAttributes.None), relation: relation)
@@ -571,4 +594,4 @@ internal class ConstraintDescription: ConstraintDescriptionExtendable, Constrain
         self.constant = other
         return constrainTo(ConstraintItem(object: nil, attributes: ConstraintAttributes.None), relation: relation)
     }
-}
+}