Ich habe mithilfe von Interface Builder Constraints zu Sichten hinzugefügt. Später im Lauf muss ich sie entfernen und neue hinzufügen. Hier ist, wie ich Einschränkungen aktualisieren:Objective C - Constraints kehren zurück, nachdem sie entfernt wurden
for (UIView *view in _fromProduitView.subviews) {
[view removeConstraints:view.constraints];
for (NSLayoutConstraint *constraint in _fromProduitView.constraints) {
if ([[constraint firstItem] isKindOfClass:[UILabel class]]) {
[_fromProduitView removeConstraint:constraint];
}
}
}
[_fromProduitView addConstraint:[NSLayoutConstraint constraintWithItem:_fonctionLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:_fromProduitView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
[_fromProduitView addConstraint:[NSLayoutConstraint constraintWithItem:_fonctionLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_fromProduitView attribute:NSLayoutAttributeLeading multiplier:1.0f constant:16]];
[_fromProduitView addConstraint:[NSLayoutConstraint constraintWithItem:_artisanNameLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:_fromProduitView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
[_fromProduitView addConstraint:[NSLayoutConstraint constraintWithItem:_artisanNameLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_fonctionLabel attribute:NSLayoutAttributeBottom multiplier:1.0f constant:8]];
[_fromProduitView addConstraint:[NSLayoutConstraint constraintWithItem:_supplierAccrocheLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:_fromProduitView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
[_fromProduitView addConstraint:[NSLayoutConstraint constraintWithItem:_supplierAccrocheLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_artisanNameLabel attribute:NSLayoutAttributeBottom multiplier:1.0f constant:8]];
An diesem Punkt log ich die Zwänge der Ansicht _fromProductView
, die die Superview ist:
<__NSArrayI 0x7fdc2df84cc0>(
<NSLayoutConstraint:0x7fdc2dfa2d40 UIView:0x7fdc2dfa59e0.height == 0>,
<NSLayoutConstraint:0x7fdc2db32320 UILabel:0x7fdc2dfa4730.centerX == UIView:0x7fdc2dfa59e0.centerX>,
<NSLayoutConstraint:0x7fdc2e9f3210 UILabel:0x7fdc2dfa4730.top == UIView:0x7fdc2dfa59e0.leading + 16>,
<NSLayoutConstraint:0x7fdc2df84960 UILabel:0x7fdc2dfb0d60.centerX == UIView:0x7fdc2dfa59e0.centerX>,
<NSLayoutConstraint:0x7fdc2cff0b90 UILabel:0x7fdc2dfb0d60.top == UILabel:0x7fdc2dfa4730.bottom + 8>,
<NSLayoutConstraint:0x7fdc2e9f38b0 UILabel:0x7fdc2dfa4c30.centerX == UIView:0x7fdc2dfa59e0.centerX>,
<NSLayoutConstraint:0x7fdc2e9f4390 UILabel:0x7fdc2dfa4c30.top == UILabel:0x7fdc2dfb0d60.bottom + 8>
)
Welches ist die Art, wie ich will, ist, aber das Problem ist, , später die contraints entfernte ich habe zurück und Konflikt mit denen komme ich schaffen haben, welche die Ergebnisse der Blick verschwinden:
<__NSArrayI 0x7fdc2b5f7460>(
<NSLayoutConstraint:0x7fdc2dfa2d40 UIView:0x7fdc2dfa59e0.height == 0>,
<NSLayoutConstraint:0x7fdc2e9f3210 UILabel:0x7fdc2dfa4730.top == UIView:0x7fdc2dfa59e0.leading + 16>,
<NSLayoutConstraint:0x7fdc2df84960 UILabel:0x7fdc2dfb0d60.centerX == UIView:0x7fdc2dfa59e0.centerX>,
<NSLayoutConstraint:0x7fdc2e9f38b0 UILabel:0x7fdc2dfa4c30.centerX == UIView:0x7fdc2dfa59e0.centerX>,
<NSLayoutConstraint:0x7fdc2dfa2de0 UILabel:0x7fdc2dfa4730.centerX == UIView:0x7fdc2dfa59e0.centerX - 8>,
<NSLayoutConstraint:0x7fdc2dfa2e30 UILabel:0x7fdc2dfa4730.leading == UILabel:0x7fdc2dfb0d60.leading>,
<NSLayoutConstraint:0x7fdc2dfa2ed0 UILabel:0x7fdc2dfb0d60.top == UILabel:0x7fdc2dfa4730.bottom + 2>,
<NSLayoutConstraint:0x7fdc2dfa2f70 UILabel:0x7fdc2dfa4c30.leading == UILabel:0x7fdc2dfb0d60.leading>,
<NSLayoutConstraint:0x7fdc2dfa2fc0 UILabel:0x7fdc2dfa4c30.top == UILabel:0x7fdc2dfb0d60.bottom>,
<NSLayoutConstraint:0x7fdc2cff0b90 UILabel:0x7fdc2dfb0d60.top == UILabel:0x7fdc2dfa4730.bottom + 8>,
<NSLayoutConstraint:0x7fdc2e9f4390 UILabel:0x7fdc2dfa4c30.top == UILabel:0x7fdc2dfb0d60.bottom + 8>,
<NSLayoutConstraint:0x7fdc2db32320 UILabel:0x7fdc2dfa4730.centerX == UIView:0x7fdc2dfa59e0.centerX>
)
So vor allem, was ich verstehe nicht, wie man Constraints dauerhaft löscht und wie View aktualisiert wird, wenn neue hinzugefügt werden
Wenn Sie alle Einschränkungen entfernen, sollten Sie sie nicht von Anfang an in IB hinzufügen? –
Versuchen Sie zunächst, die Einschränkungen zu deaktivieren und dann neue anzuwenden. Sie können die Einschränkung einfach deaktivieren, indem Sie die Eigenschaft 'active' auf' NO' setzen. –
Ich entferne nicht alle Beschränkungen, die 'superView' enthält andere Ansichten neben denen. Außerdem geschieht dieses Szenario nur, wenn einige "seltene" Bedingungen erfüllt sind. –