2014-10-03 2 views
5

UICollectionViewCell 내에서 autolayout을 사용하고 있습니다. 슈퍼 간단한 레이아웃 : 그냥 UILabel. 나는 UILabel이 전폭에서 20 px 인세트를 뺀 것을 세로 및 가로로 셀 중앙에두기를 원합니다. 나는 그런 제약을 설정했다. ios 8 장치 나 시뮬레이터에서 실행하면 완벽하게 작동합니다. 그러나, 일부 iOS 7 디바이스에서 실행할 때 제약 조건이 적용되지 않습니다. 애플 문서를 살펴 보았지만 자동 레이아웃과 관련된 변경 사항은 없습니다. 답변보다 해결의AutoLayout은 ios 8에서는 작동하지만 ios 7에서는 작동하지 않습니까?

<constraints> 
      <constraint firstItem="OIc-cg-9hO" firstAttribute="leading" secondItem="Ga6-nx-lOn" secondAttribute="leading" constant="20" id="A7U-sd-fcL"/> 
      <constraint firstAttribute="centerY" secondItem="OIc-cg-9hO" secondAttribute="centerY" id="G9e-9W-aDS"/> 
      <constraint firstAttribute="centerX" secondItem="OIc-cg-9hO" secondAttribute="centerX" id="TrB-hI-7Kw"/> 
      <constraint firstAttribute="trailing" secondItem="OIc-cg-9hO" secondAttribute="trailing" constant="20" id="yjH-nf-D9U"/> 
     </constraints> 

더 : 나는 그것이 훨씬 의미 의심하지만 여기

는 XML 소스 코드입니다하지만 다음과 같이 나는 코드에서 제약 조건을 추가 :

[self addConstraint:[NSLayoutConstraint constraintWithItem:self.cellName 
                 attribute:NSLayoutAttributeWidth 
                 relatedBy:NSLayoutRelationEqual 
                 toItem:self 
                 attribute:NSLayoutAttributeWidth 
                multiplier:1.0 
                 constant:-20.0]]; 

[self addConstraint:[NSLayoutConstraint constraintWithItem:self.cellName 
                 attribute:NSLayoutAttributeCenterX 
                 relatedBy:NSLayoutRelationEqual 
                 toItem:self 
                 attribute:NSLayoutAttributeCenterX 
                multiplier:1.0 
                 constant:0.0]]; 

[self addConstraint:[NSLayoutConstraint constraintWithItem:self.cellName 
                 attribute:NSLayoutAttributeCenterY 
                 relatedBy:NSLayoutRelationEqual 
                 toItem:self 
                 attribute:NSLayoutAttributeCenterY 
                multiplier:1.0 
                 constant:0.0]]; 

위해 그것이 작동하려면 코드 된 제약 조건과 IB 제약 조건이 모두 필요했습니다. Dunno 왜!

+0

당신이 아이폰 OS 7 어떤 결과를 얻을 수 있습니까? iOS 7에서는 작동하지 않아야하는 제약 사항이 없습니다. – rdelmar

+0

UILabel은 xib의 정확한 높이와 너비를 가지고 있습니다. – user3534641

+1

동일한 설치 및 문제가 있습니다. 아직 어떤 해결책이 있습니까? – Ravi

답변

5

iOS7에서 지원되지 않는 인터페이스 제약 조건 제약 조건 인 "여백 제한"옵션이 사용 된 것처럼 들립니다. IB에서 제약 조건을 열고 'margin to relative'옵션이 선택된 항목이 있는지 확인하십시오.

한계 여백에 대한 자세한 내용은 What is "Constrain to margin" in Storyboard in Xcode 6What is "Constrain to margin" in Storyboard in Xcode 6을 참조하십시오.

+1

그 옵션을 찾을 수조차 없지만 xml에 아무것도 없습니다. – user3534641

+0

올바른 방향으로 인도합니다. –

4

이것은 나에게 일어났습니다. UI의 모든 제약 조건을 확인하고 iOS 8에 도입 된 상대적인 증거금을 제거하고 iOS 7을 지원하지 않아야합니다. 잊어 버릴 수도있는 곳을 잊지 마세요. (UITableView 셀과 같이).

이 옵션을 찾으려면 다음 UI 컨트롤 크기 경위에

  • 이동에

    1. 탭을

    2. 더블 그냥 전원을 끄고 모든 제약 조건을 클릭하고 여백 것을 확인 변경 사항이있을 경우 제약 조건을 수정하십시오.

    enter image description here

  • 관련 문제