UIView 是否创建一个intrinsicContentSize
?
我创建了一个 UIView 内容视图。我不给它限制大小:
UIView *contentView = [UIView new];
[contentView setTranslatesAutoresizingMaskIntoConstraints:NO];
contentView.backgroundColor = [UIColor orangeColor];
我创建了另一个 UIView subview01。我给它约束大小并将其添加到我的 contentView 中:
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[imageView setTranslatesAutoresizingMaskIntoConstraints:NO];
imageView.userInteractionEnabled = TRUE;
imageView.backgroundColor = [UIColor clearColor];
[imageView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[imageView(WIDTH)]"
options:0
metrics:@{@"WIDTH" : [NSNumber numberWithFloat:imageSize.width]}
views:NSDictionaryOfVariableBindings(imageView)]];
[imageView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[imageView(HEIGHT)]"
options:0
metrics:@{@"HEIGHT" : [NSNumber numberWithFloat:imageSize.height]}
views:NSDictionaryOfVariableBindings(imageView)]];
[contentView addSubview:imageView];
contentView 不会获得任何大小。我认为intrinsicContentSize
应该计算显示所有子视图所需的大小并调整自身大小?就像 UILabel 将如何调整大小以显示其所有文本一样?