From 4abf189fc9a7278cb8ab1812b9cc30f7e12e9672 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Tue, 5 Aug 2014 18:51:42 +1200 Subject: [PATCH] Allow automagic constraining --- Snappy/Constraint.swift | 9 ++++++--- SnappyExample/ViewController.swift | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) 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)) }