0001 // 0002 // SnapKit 0003 // 0004 // Copyright (c) 2011-2015 SnapKit Team - https://github.com/SnapKit 0005 // 0006 // Permission is hereby granted, free of charge, to any person obtaining a copy 0007 // of this software and associated documentation files (the "Software"), to deal 0008 // in the Software without restriction, including without limitation the rights 0009 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0010 // copies of the Software, and to permit persons to whom the Software is 0011 // furnished to do so, subject to the following conditions: 0012 // 0013 // The above copyright notice and this permission notice shall be included in 0014 // all copies or substantial portions of the Software. 0015 // 0016 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0017 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0018 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0019 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0020 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0021 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 0022 // THE SOFTWARE. 0023 0024 #if os(iOS) || os(tvOS) 0025 import UIKit 0026 public typealias View = UIView 0027 #else 0028 import AppKit 0029 public typealias View= NSView 0030 #endif 0031 0032 /** 0033 Used to expose public API on views 0034 */ 0035 public extension View { 0036 0037 /// left edge 0038 public var snp_left: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Left) } 0039 0040 /// top edge 0041 public var snp_top: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Top) } 0042 0043 /// right edge 0044 public var snp_right: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Right) } 0045 0046 /// bottom edge 0047 public var snp_bottom: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Bottom) } 0048 0049 /// leading edge 0050 public var snp_leading: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Leading) } 0051 0052 /// trailing edge 0053 public var snp_trailing: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Trailing) } 0054 0055 /// width dimension 0056 public var snp_width: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Width) } 0057 0058 /// height dimension 0059 public var snp_height: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Height) } 0060 0061 /// centerX position 0062 public var snp_centerX: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterX) } 0063 0064 /// centerY position 0065 public var snp_centerY: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterY) } 0066 0067 /// baseline position 0068 public var snp_baseline: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Baseline) } 0069 0070 /// first baseline position 0071 @available(iOS 8.0, *) 0072 public var snp_firstBaseline: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.FirstBaseline) } 0073 0074 /// left margin 0075 @available(iOS 8.0, *) 0076 public var snp_leftMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.LeftMargin) } 0077 0078 /// right margin 0079 @available(iOS 8.0, *) 0080 public var snp_rightMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.RightMargin) } 0081 0082 /// top margin 0083 @available(iOS 8.0, *) 0084 public var snp_topMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.TopMargin) } 0085 0086 /// bottom margin 0087 @available(iOS 8.0, *) 0088 public var snp_bottomMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.BottomMargin) } 0089 0090 /// leading margin 0091 @available(iOS 8.0, *) 0092 public var snp_leadingMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.LeadingMargin) } 0093 0094 /// trailing margin 0095 @available(iOS 8.0, *) 0096 public var snp_trailingMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.TrailingMargin) } 0097 0098 /// centerX within margins 0099 @available(iOS 8.0, *) 0100 public var snp_centerXWithinMargins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterXWithinMargins) } 0101 0102 /// centerY within margins 0103 @available(iOS 8.0, *) 0104 public var snp_centerYWithinMargins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterYWithinMargins) } 0105 0106 // top + left + bottom + right edges 0107 public var snp_edges: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Edges) } 0108 0109 // width + height dimensions 0110 public var snp_size: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Size) } 0111 0112 // centerX + centerY positions 0113 public var snp_center: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Center) } 0114 0115 // top + left + bottom + right margins 0116 @available(iOS 8.0, *) 0117 public var snp_margins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Margins) } 0118 0119 // centerX + centerY within margins 0120 @available(iOS 8.0, *) 0121 public var snp_centerWithinMargins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterWithinMargins) } 0122 0123 /** 0124 Prepares constraints with a `ConstraintMaker` and returns the made constraints but does not install them. 0125 0126 :param: closure that will be passed the `ConstraintMaker` to make the constraints with 0127 0128 :returns: the constraints made 0129 */ 0130 public func snp_prepareConstraints(file: String = __FILE__, line: UInt = __LINE__, @noescape closure: (make: ConstraintMaker) -> Void) -> [Constraint] { 0131 return ConstraintMaker.prepareConstraints(view: self, file: file, line: line, closure: closure) 0132 } 0133 0134 /** 0135 Makes constraints with a `ConstraintMaker` and installs them along side any previous made constraints. 0136 0137 :param: closure that will be passed the `ConstraintMaker` to make the constraints with 0138 */ 0139 public func snp_makeConstraints(file: String = __FILE__, line: UInt = __LINE__, @noescape closure: (make: ConstraintMaker) -> Void) -> Void { 0140 ConstraintMaker.makeConstraints(view: self, file: file, line: line, closure: closure) 0141 } 0142 0143 /** 0144 Updates constraints with a `ConstraintMaker` that will replace existing constraints that match and install new ones. 0145 0146 For constraints to match only the constant can be updated. 0147 0148 :param: closure that will be passed the `ConstraintMaker` to update the constraints with 0149 */ 0150 public func snp_updateConstraints(file: String = __FILE__, line: UInt = __LINE__, @noescape closure: (make: ConstraintMaker) -> Void) -> Void { 0151 ConstraintMaker.updateConstraints(view: self, file: file, line: line, closure: closure) 0152 } 0153 0154 /** 0155 Remakes constraints with a `ConstraintMaker` that will first remove all previously made constraints and make and install new ones. 0156 0157 :param: closure that will be passed the `ConstraintMaker` to remake the constraints with 0158 */ 0159 public func snp_remakeConstraints(file: String = __FILE__, line: UInt = __LINE__, @noescape closure: (make: ConstraintMaker) -> Void) -> Void { 0160 ConstraintMaker.remakeConstraints(view: self, file: file, line: line, closure: closure) 0161 } 0162 0163 /** 0164 Removes all previously made constraints. 0165 */ 0166 public func snp_removeConstraints() { 0167 ConstraintMaker.removeConstraints(view: self) 0168 } 0169 0170 internal var snp_installedLayoutConstraints
Constraint.swift:208 var installOnView: View? = nilConstraint.swift:241 let layoutFrom: View? = self.fromItem.viewConstraint.swift:375 weak var view: View? = nilConstraint.swift:470 private func closestCommonSuperviewFromView(fromView: View?, toView: View?) -> View? {Constraint.swift:470 private func closestCommonSuperviewFromView(fromView: View?, toView: View?) -> View? {Constraint.swift:470 private func closestCommonSuperviewFromView(fromView: View?, toView: View?) -> View? {Constraint.swift:471 var views = Set<View>()ConstraintDescription.swift:95 func equalTo(other: View) -> ConstraintDescriptionEditableConstraintDescription.swift:110 func lessThanOrEqualTo(other: View) -> ConstraintDescriptionEditableConstraintDescription.swift:125 func greaterThanOrEqualTo(other: View) -> ConstraintDescriptionEditableConstraintDescription.swift:226 internal func equalTo(other: View) -> ConstraintDescriptionEditable {ConstraintDescription.swift:267 internal func lessThanOrEqualTo(other: View) -> ConstraintDescriptionEditable {ConstraintDescription.swift:308 internal func greaterThanOrEqualTo(other: View) -> ConstraintDescriptionEditable {ConstraintDescription.swift:559 private func constrainTo(other: View, relation: ConstraintRelation) -> ConstraintDescription {ConstraintItem.swift:44 return self.object as? ViewConstraintItem.swift:43 internal var view: View? {ConstraintMaker.swift:121 internal init(view: View, file: String, line: UInt) {ConstraintMaker.swift:129 internal let view: ViewConstraintMaker.swift:139 internal class func prepareConstraints(view view: View, file: String = "Unknown", line: UInt = 0, @noescape closure: (make: ConstraintMaker) -> Void) -> [Constraint] {ConstraintMaker.swift:151 internal class func makeConstraints(view view: View, file: String = "Unknown", line: UInt = 0, @noescape closure: (make: ConstraintMaker) -> Void) {ConstraintMaker.swift:164 internal class func remakeConstraints(view view: View, file: String = "Unknown", line: UInt = 0, @noescape closure: (make: ConstraintMaker) -> Void) {ConstraintMaker.swift:178 internal class func updateConstraints(view view: View, file: String = "Unknown", line: UInt = 0, @noescape closure: (make: ConstraintMaker) -> Void) {ConstraintMaker.swift:191 internal class func removeConstraints(view view: View) {Debugging.swift:33 public extension View {Debugging.swift:121 if let object = object as? View {View+SnapKit.swift:35 public extension View {: [LayoutConstraint] { 0171 get { 0172 if let constraints = objc_getAssociatedObject(self, &installedLayoutConstraintsKey) as? [LayoutConstraint] { 0173 return constraints 0174 } 0175 return [] 0176 } 0177 set { 0178 objc_setAssociatedObject(self, &installedLayoutConstraintsKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) 0179 } 0180 } 0181 } 0182 0183 private var installedLayoutConstraintsKey
Constraint.swift:285 let existingLayoutConstraints = layoutFrom!.snp_installedLayoutConstraints.reverse()Constraint.swift:337 layoutFrom!.snp_installedLayoutConstraints += newLayoutConstraintsConstraint.swift:361 fromView.snp_installedLayoutConstraints = fromView.snp_installedLayoutConstraints.filter {Constraint.swift:361 fromView.snp_installedLayoutConstraints = fromView.snp_installedLayoutConstraints.filter {ConstraintMaker.swift:192 for existingLayoutConstraint in view.snp_installedLayoutConstraints {= "" 0184
View+SnapKit.swift:172 if let constraints = objc_getAssociatedObject(self, &installedLayoutConstraintsKey) as? [LayoutConstraint] {View+SnapKit.swift:178 objc_setAssociatedObject(self, &installedLayoutConstraintsKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)