Trong một số dự án mà tôi cố gắng tìm hiểu có một số mã:SetTranslatesAutoresizingMaskIntoConstraints: NO cho là gì?
[[[self foregroundContentView] contentView] addSubview:[self hueLabel]];
[[[self foregroundContentView] contentView] addSubview:[self hueSlider]];
[[[self foregroundContentView] contentView] addSubview:[self saturationLabel]];
[[[self foregroundContentView] contentView] addSubview:[self saturationSlider]];
[[[self foregroundContentView] contentView] addSubview:[self brightnessLabel]];
[[[self foregroundContentView] contentView] addSubview:[self brightnessSlider]];
[[[self foregroundContentView] contentView] addSubview:[self saveButton]];
[[self foregroundContentScrollView] addSubview:[self foregroundContentView]];
[[self foregroundContentScrollView] addSubview:[self imageView]];
[[self view] addSubview:[self backgroundView]];
[[self view] addSubview:[self foregroundContentScrollView]];
Mỗi điểm có một bộ tài sản setTranslatesAutoresizingMaskIntoConstraints
để NO
, ví dụ:
[[self saveButton] setTranslatesAutoresizingMaskIntoConstraints:NO];
Sau đó, nó cho biết thêm một số trở ngại đối với những quan điểm :
NSDictionary* views = @{
@"backgroundView" : [self backgroundView],
@"foregroundContentScrollView" : [self foregroundContentScrollView],
@"foregroundContentView" : [self foregroundContentView],
@"hueLabel" : [self hueLabel],
@"hueSlider" : [self hueSlider],
@"saturationLabel" : [self saturationLabel],
@"saturationSlider" : [self saturationSlider],
@"brightnessLabel" : [self brightnessLabel],
@"brightnessSlider" : [self brightnessSlider],
@"saveButton" : [self saveButton],
@"imageView" : [self imageView]
};
[[self view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[backgroundView]|" options:0 metrics:nil views:views]];
[[self view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[backgroundView]|" options:0 metrics:nil views:views]];
[[self view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[foregroundContentScrollView]|" options:0 metrics:nil views:views]];
[[self view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[foregroundContentScrollView]|" options:0 metrics:nil views:views]];
[[self view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[foregroundContentView]|" options:0 metrics:nil views:views]];
[[self view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[foregroundContentView]|" options:0 metrics:nil views:views]];
[[self view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[hueLabel]-|" options:0 metrics:nil views:views]];
[[self view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[hueSlider]-|" options:0 metrics:nil views:views]];
[[self view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[saturationLabel]-|" options:0 metrics:nil views:views]];
[[self view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[saturationSlider]-|" options:0 metrics:nil views:views]];
[[self view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[brightnessLabel]-|" options:0 metrics:nil views:views]];
[[self view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[brightnessSlider]-|" options:0 metrics:nil views:views]];
[[self view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[saveButton]-|" options:0 metrics:nil views:views]];
[[self view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[imageView(==foregroundContentScrollView)]|" options:0 metrics:nil views:views]];
[[self view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(>=30)-[hueLabel]-[hueSlider]-[saturationLabel]-[saturationSlider]-[brightnessLabel]-[brightnessSlider]-[saveButton]-(>=10)-[imageView(==200)]|" options:0 metrics:nil views:views]];
Các câu hỏi là:
setTranslatesAutoresizingMaskIntoConstraints:NO
là gì? Tại sao khi tôi loại bỏ một trong những dòng với phương pháp đó, sau đó tất cả mọi thứ bị hỏng?dòng đó làm gì?
[[self view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[foregroundContentScrollView]|" options:0 metrics:nil views:views]];
Ý bạn là gì theo cách tiếp cận * lò xo và thanh chống *? – Honey
Đó là cách thông tục mô tả cơ chế tự động hóa trước khi bố cục tự động được giới thiệu. Một mô tả các khía cạnh nào về kích thước của khung nhìn và quan hệ với người giám sát của nó là linh hoạt (giống như mùa xuân) và được cố định (kiểu tương tự) bằng cách sử dụng mặt nạ tự động hóa. Xem 'autoresizingMask' và' autoresizesSubviews'. –