diff --git a/Snappy/Constraint.swift b/Snappy/Constraint.swift index f7bd4bd..ee1e93a 100644 --- a/Snappy/Constraint.swift +++ b/Snappy/Constraint.swift @@ -323,9 +323,6 @@ class Constraint { // get layout from let layoutFrom: View? = self.fromItem.view - // get layout to - let layoutTo: View? = self.toItem.view - // get layout relation let layoutRelation: NSLayoutRelation = (self.relation != nil) ? self.relation!.layoutRelation : .Equal @@ -337,6 +334,12 @@ class Constraint { var layoutConstant: CGFloat = layoutToAttribute.snp_constantForValue(self.constant) layoutConstant += layoutToAttribute.snp_offsetForValue(self.offset) + // get layout to + var layoutTo: View? = self.toItem.view + if layoutTo == nil && layoutToAttribute != .Width && layoutToAttribute != .Height { + layoutTo = installOnView + } + // create layout constraint let layoutConstraint = LayoutConstraint( item: layoutFrom, diff --git a/SnappyExample/ViewController.swift b/SnappyExample/ViewController.swift index 9eca6e3..4dc0ad5 100644 --- a/SnappyExample/ViewController.swift +++ b/SnappyExample/ViewController.swift @@ -37,7 +37,7 @@ class ViewController: UIViewController { view1.snp_makeConstraints { make in - make.top.and.left.equalTo(superview).insets(padding) + make.top.and.left.equalTo(CGPointZero).insets(padding) make.size.equalTo(CGSizeMake(100, 50)) }