iOS 7에서는 작동하지만 iOS 8에서는 작동하지 않는 자동 레이아웃 코드가 있습니다. 두 가지 버전 간에는 내 코드가 변경되지 않았습니다. 나는 아이폰 OS 8에서 동일한 코드를 실행하면iOS 8 : NSLayoutAttributeCenterX에서 내보기를 가운데 놓지 않는 이유는 무엇입니까? (iOS 7에서 작동)
그러나
가, 다음이 발생합니다
상황은 내가 지금처럼 수직으로 쌓아해야 할 몇 가지 서브 뷰를 포함하는 뷰 컨트롤러를 가지고있다 :
는다음 내 제약 조건을 설정하는 코드가 될 때 :
- (void) updateViewConstraints {
[super updateViewConstraints];
NSDictionary *viewsDictionary = @{
@"timeLabel": self.timeLabel,
@"recordingStateImage": self.recordingStateImage,
@"recordButton": self.recordButton,
@"spacer1": spacer1,
@"spacer2": spacer2,
@"superview": self.view
};
if (!portraitConstraints) {
//
// Portrait Layout
//
portraitConstraints = [[NSMutableArray alloc] initWithArray:
[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[timeLabel][spacer1][recordingStateImage][spacer2(==spacer1)][recordButton(100)]-|"
options:0
metrics:0
views:viewsDictionary]];
[portraitConstraints addObjectsFromArray:@[
[NSLayoutConstraint constraintWithItem:self.timeLabel
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterX
multiplier:1.f
constant:0.f],
[NSLayoutConstraint constraintWithItem:self.recordingStateImage
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterX
multiplier:1.f
constant:0.f],
[NSLayoutConstraint constraintWithItem:self.recordButton
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterX
multiplier:1.f
constant:0.f]
]];
}
[self.view removeConstraints:self.view.constraints];
[self.view addConstraints:portraitConstraints];
}
왜 이런 일이 발생하는지 잘 모르겠습니다. 나는 그래서 다음 질문에서 언급 한 해결 방법을 살펴 보았다 :
- Autolayout problems with iOS8 with code that works fine on iOS7
- Issue with Auto Layout on iOS 8 (code works perfectly on iOS 7)
그러나 그들은 (대신 뷰 컨트롤러의 뷰의 서브 뷰에 setNeedsLayout를 호출하는) 일을하지 않았습니다.
NSLayoutAttributeCenterX 및 iOS 8의 자동 레이아웃과 관련된 문제가있는 사람은 누구나 문의 해 주시면 감사하겠습니다.
여기에 컨테이너보기가 무엇입니까 ??? –
언제 updateViewConstraints를 호출합니까? viewDidLoad 또는 ViewWillAppear와 같은 라이프 사이클 방식입니까? – kpsharp
updateViewConstraints의 모든 제약 조건을 제거하지 마십시오. XCode에 의해 추가 된 제약 조건도 제거되므로 다시 얻지 못할 것입니다. – Jageen