From 7e8c1732242de2228988001efc71db6ad7bb3415 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Tue, 16 Aug 2016 23:24:14 +1200 Subject: [PATCH] Allow implied superview for equalTo(constant) --- Source/Constraint.swift | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/Source/Constraint.swift b/Source/Constraint.swift index 5455932..d0fae6f 100644 --- a/Source/Constraint.swift +++ b/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) -//}