forked from robb/Cartography
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConstraintGroup.swift
44 lines (36 loc) · 979 Bytes
/
ConstraintGroup.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// ConstraintGroup.swift
// Cartography
//
// Created by Robert Böhnke on 22/01/15.
// Copyright (c) 2015 Robert Böhnke. All rights reserved.
//
import Foundation
public class ConstraintGroup {
private var constraints: [Constraint] = []
@available(OSX, introduced=10.10)
@available(iOS, introduced=8.0)
public var active: Bool {
get {
return constraints
.map { $0.layoutConstraint.active }
.reduce(true) { $0 && $1 }
}
set {
for constraint in constraints {
constraint.layoutConstraint.active = newValue
}
}
}
public init() {
}
internal func replaceConstraints(constraints: [Constraint]) {
for constraint in self.constraints {
constraint.uninstall()
}
self.constraints = constraints
for constraint in self.constraints {
constraint.install()
}
}
}