텍스트의 길이에 따라 높이를 설정하는 UICollectionViewCell 하위 클래스에 코드의 높이 레이아웃 제약 조건을 추가했습니다. See this question. 높이 계산을위한 코드를 게시 할 수는 있지만 처음 4 개의 셀은 완벽하게 작동하지만 5 번째 셀은 충돌하기 때문에 문제는 아니라고 생각합니다.추가 높이 제약으로 인해 Autolayout이 충돌 함
@property (weak, nonatomic) UILabel *name;
이것은 제약 조건을 만드는 방법입니다.
NSLayoutConstraint *labelHeightContraint = [NSLayoutConstraint constraintWithItem:self.name attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:labelSize.height];
[self.name addConstraint:labelHeightContraint];
그리고 이것은 내가 얻는 오류입니다.
Unable to simultaneously satisfy constraints.
(
"<NSLayoutConstraint:0x9ff8770 V:[UILabel:0x9ff72d0(60.843)]>",
"<NSLayoutConstraint:0x9feb590 V:[UILabel:0x9ff72d0(40.562)]>"
)
나에게는 2 개의 높이 제한이있는 것으로 보입니다. 인터페이스 빌딩에는 높이 제한이 없습니다 (스크린 샷 참조).
충돌 전에 제한을 인쇄하면 높이 제한이 표시됩니다.
<__NSArrayM 0x9eb0a00>(
<NSLayoutConstraint:0x9ea1670 V:[UILabel:0x9eb2e30(60.843)]>,
<NSContentSizeLayoutConstraint:0x9fa0580 H:[UILabel:0x9eb2e30(72)] Hug:251 CompressionResistance:750>,
<NSContentSizeLayoutConstraint:0x9fa7bf0 V:[UILabel:0x9eb2e30(61)] Hug:251 CompressionResistance:750>
)
내가 계산 제약은
<NSLayoutConstraint:0x9ea9b50 V:[UILabel:0x9eb2e30(40.562)]>
귀하의 답변은 도움이나 코드 또는 일부 설명으로 연결되어야합니다. 이것은 대답으로 취급 될 수 없다 –
UILabel의'height'를 가진이 간단한 충돌'CompressionResistance'. 이 저자는 중복으로 게임을해야합니다 – Bimawa
이전에 이것을 시도했지만 충돌을 멈추었지만 문제를 해결하지 못했습니다. – Kevin