如果子視圖被固定到超級視圖的邊緣,並且其內容大於超級視圖(可能是您的情況),那麼如果您使用的是可視格式語言。
例如,假設您的childView是一個UIImageView,並具有圖像與尺寸1024×1024
如果你的汽車的佈局是一樣的東西:
[self.wrapperView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[imageView]|" options:0 metrics:nil views:views]];
那麼你的ImageView將推動wrapperView出。
你需要做的是使用約束的這種方法,這是一個比較明確的:
[self.wrapperView addConstraint:[NSLayoutConstraint constraintWithItem:self.childView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.wrapperView attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0.0]];
這告訴自動佈局,你的孩子視圖的寬度應該等於包裝視圖的寬度,從不大於(由NSRelationEqual標誌指定)。
不,沒有比superview更大的東西。 –