0
제 생각에는 viewDidAppear
과 실행중인 인터페이스 요소의 제약 사이에 지연이있는 것 같습니다.iOS autolayout 인터페이스 제약 조건은 언제 실행됩니까?
나는 내용물에 따라 크기가 달라지는 UILabel
입니다. viewDidAppear
에서 제약 조건을 확인하면 비어 있습니다. 내가 500ms를 기다린 후 (예를 들어) 다시 확인하면 제약 조건이 예상대로 유지됩니다. UILabel
의 경계에 대해서도 마찬가지입니다. 즉각적인 사용은 없으며, 일단 제약 조건이 실행되면 예상대로 설정됩니다.
내 코드 :
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// Get constraints and bounds
NSLog(@"description constraints a %@", [descriptionLabel constraints]);
NSLog(@"description bounds a %@", NSStringFromCGRect([descriptionLabel bounds]));
// Wait a bit, then get constraints
double delayInSeconds = 0.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {
NSLog(@"description constraints b %@", [descriptionLabel constraints]);
NSLog(@"description bounds b %@", NSStringFromCGRect([descriptionLabel bounds]));
});
}
그리고 그 코드의 출력 :
10:39:35.949 Abc[2550:949660 constraints a (
)
10:39:35.950 Abc[2550:949660 bounds a {{0, 0}, {42, 21}}
10:39:36.480 Abc[2550:949660 constraints b (
"<NSContentSizeLayoutConstraint:0x175c0310 H:[UILabel:0x176d5080'elit ipsum amet ut cillum...'(290)] Hug:251 CompressionResistance:750>",
"<NSContentSizeLayoutConstraint:0x175c0350 V:[UILabel:0x176d5080'elit ipsum amet ut cillum...'(629)] Hug:251 CompressionResistance:750>"
)
10:39:36.482 Abc[2550:949660] description bounds b {{0, 0}, {290, 629}}
{42, 21}
iOS 8.1을 실행하는 iPod Touch에서 실행중인 iOS 7.1을 타겟팅하는 Xcode 6.1을 사용하고 있습니다. 뷰 컨트롤러에 대한