fix "Mutating a priority from required to not on an installed constra… (#323)

* fix "Mutating a priority from required to not on an installed constraint (or vice-versa) is not supported." when the priority is not changed

* add more check when changing layout constraint priority

* add more lenient check when changing layout constraint priority

* fix UILayoutPriorityRequired available only on iOS

* fix undeclared UILayoutPriority on macOS

* add check for tvOS
This commit is contained in:
vhosune 2016-09-23 12:54:49 +02:00 committed by Robert Payne
parent 25cf3bede1
commit 3f529652a4
1 changed files with 11 additions and 1 deletions

View File

@ -228,9 +228,19 @@ public class Constraint {
for layoutConstraint in self.layoutConstraints { for layoutConstraint in self.layoutConstraints {
let attribute = (layoutConstraint.secondAttribute == .notAnAttribute) ? layoutConstraint.firstAttribute : layoutConstraint.secondAttribute let attribute = (layoutConstraint.secondAttribute == .notAnAttribute) ? layoutConstraint.firstAttribute : layoutConstraint.secondAttribute
layoutConstraint.constant = self.constant.constraintConstantTargetValueFor(layoutAttribute: attribute) layoutConstraint.constant = self.constant.constraintConstantTargetValueFor(layoutAttribute: attribute)
#if os(iOS) || os(tvOS)
let requiredPriority: UILayoutPriority = UILayoutPriorityRequired
#else
let requiredPriority: Float = 1000.0
#endif
if (layoutConstraint.priority < requiredPriority), (self.priority.constraintPriorityTargetValue != requiredPriority) {
layoutConstraint.priority = self.priority.constraintPriorityTargetValue layoutConstraint.priority = self.priority.constraintPriorityTargetValue
} }
} }
}
internal func activateIfNeeded(updatingExisting: Bool = false) { internal func activateIfNeeded(updatingExisting: Bool = false) {
guard let view = self.from.view else { guard let view = self.from.view else {