Commit 8225dd36 by Orkhan Alikhanov

Added layout relation

parent 091e1086
...@@ -83,6 +83,7 @@ private extension NSLayoutConstraint { ...@@ -83,6 +83,7 @@ private extension NSLayoutConstraint {
&& secondItem === other.secondItem && secondItem === other.secondItem
&& firstAttribute == other.firstAttribute && firstAttribute == other.firstAttribute
&& secondAttribute == other.secondAttribute && secondAttribute == other.secondAttribute
&& relation == other.relation
} }
} }
...@@ -1121,7 +1122,7 @@ private extension Layout { ...@@ -1121,7 +1122,7 @@ private extension Layout {
let v = (anchor as? UIView) ?? (anchor as? LayoutAnchor)?.constraintable let v = (anchor as? UIView) ?? (anchor as? LayoutAnchor)?.constraintable
to = LayoutAnchor(constraintable: v, attributes: attributes) to = LayoutAnchor(constraintable: v, attributes: attributes)
} }
let constraint = LayoutConstraint(fromAnchor: from, toAnchor: to!, constants: constants) let constraint = LayoutConstraint(fromAnchor: from, toAnchor: to!, relation: .equal, constants: constants)
let constraints = (view?.constraints ?? []) + (view?.superview?.constraints ?? []) let constraints = (view?.constraints ?? []) + (view?.superview?.constraints ?? [])
......
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
import UIKit import UIKit
/// A typealias for NSLayoutConstraint.Relation
public typealias LayoutRelation = NSLayoutConstraint.Relation
internal struct LayoutConstraint { internal struct LayoutConstraint {
/// `From` anchor for the constraint. /// `From` anchor for the constraint.
private let fromAnchor: LayoutAnchor private let fromAnchor: LayoutAnchor
...@@ -33,17 +36,23 @@ internal struct LayoutConstraint { ...@@ -33,17 +36,23 @@ internal struct LayoutConstraint {
private let toAnchor: LayoutAnchor private let toAnchor: LayoutAnchor
/// An array of constants for the constraint. /// An array of constants for the constraint.
private var constants: [CGFloat] private let constants: [CGFloat]
/// A LayoutRelation between anchors.
private let relation: LayoutRelation
/** /**
An initializer taking `from` and `to` anchors and constants for the constraint. An initializer taking `from` and `to` anchors, their `relation` and constants for the constraint.
- Parameter fromAnchor: A LayoutAnchor. - Parameter fromAnchor: A LayoutAnchor.
- Parameter toAnchor: A LayoutAnchor. - Parameter toAnchor: A LayoutAnchor.
- Parameter relation: A LayoutRelation between anchors.
- Parameter constants: An array of CGFloat. - Parameter constants: An array of CGFloat.
*/ */
init(fromAnchor: LayoutAnchor, toAnchor: LayoutAnchor, constants: [CGFloat]) { init(fromAnchor: LayoutAnchor, toAnchor: LayoutAnchor, relation: LayoutRelation, constants: [CGFloat]) {
self.fromAnchor = fromAnchor self.fromAnchor = fromAnchor
self.toAnchor = toAnchor self.toAnchor = toAnchor
self.relation = relation
self.constants = constants self.constants = constants
} }
} }
...@@ -64,7 +73,7 @@ internal extension LayoutConstraint { ...@@ -64,7 +73,7 @@ internal extension LayoutConstraint {
zip(zip(fromAnchor.attributes, toAnchor.attributes), constants).forEach { zip(zip(fromAnchor.attributes, toAnchor.attributes), constants).forEach {
v.append(NSLayoutConstraint(item: fromAnchor.constraintable as Any, v.append(NSLayoutConstraint(item: fromAnchor.constraintable as Any,
attribute: $0.0, attribute: $0.0,
relatedBy: .equal, relatedBy: relation,
toItem: toAnchor.constraintable, toItem: toAnchor.constraintable,
attribute: $0.1, attribute: $0.1,
multiplier: 1, multiplier: 1,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment