소스 검색

Allow implied superview for equalTo(constant)

Robert Payne 9 년 전
부모
커밋
7e8c173224
1개의 변경된 파일7개의 추가작업 그리고 18개의 파일을 삭제
  1. 7 18
      Source/Constraint.swift

+ 7 - 18
Source/Constraint.swift

@@ -87,11 +87,16 @@ public class Constraint {
             
             // get layout to
             #if os(iOS) || os(tvOS)
-                let layoutTo: AnyObject? = self.to.view ?? self.to.layoutSupport
+                var layoutTo: AnyObject? = self.to.view ?? self.to.layoutSupport
             #else
-                let layoutTo: AnyObject? = self.to.view
+                var layoutTo: AnyObject? = self.to.view
             #endif
             
+            // use superview if possible
+            if layoutTo == nil && layoutToAttribute != .width && layoutToAttribute != .height {
+                layoutTo = layoutFrom.superview
+            }
+            
             // create layout constraint
             let layoutConstraint = LayoutConstraint(
                 item: layoutFrom,
@@ -206,19 +211,3 @@ public class Constraint {
         view.snp.remove(layoutConstraints: layoutConstraints)
     }
 }
-
-//extension Constraint: Hashable {
-//    
-//    public var hashValue: Int {
-//        return self.layoutConstraints.hashValue
-//    }
-//    
-//}
-//
-//public func ==(lhs: Constraint, rhs: Constraint) -> Bool {
-//    return (lhs.from == rhs.from &&
-//            lhs.to == rhs.to &&
-//            lhs.relation == rhs.relation &&
-//            lhs.multiplier.constraintMultiplierTargetValue == rhs.multiplier.constraintMultiplierTargetValue &&
-//            lhs.priority.constraintPriorityTargetValue == rhs.priority.constraintPriorityTargetValue)
-//}