レイアウトは少し指定されていないようです。view1 のサイズに合わせるのではなく、view2 が縮小し始めるのはいつですか? ビュー1がソフト最小値に達するまで、ビューは同じサイズである必要があると想定しています。その時点で、view2 は最小値に達するまでサイズ変更され、次に view1 は最小値に達するまでサイズ変更されます。
制約に優先順位を追加することで、この動作を実現できます。重要な順に並べると、次のようになります。
- view1 と view2 >= 最小
- view1 >= view1SoftMinimum
- ビュー1 == ビュー2
制約 1 は、ウィンドウのサイズ変更の優先順位より上にある必要があります。必須にすることができます (これがデフォルトです)。
制約 2 は制約 3 より上で、NSLayoutPriorityDragThatCannotResizeWindow より下でなければなりません。480にします。
制約 3 は制約 2 より下でなければならないので、479 にします。
これらの制約はすべて、1 つの視覚的な書式文字列で表現できます。これを追加できます。
|[view1(>=view1Minimum,>=view1SoftMinimum@480,==view2@479)][view2(>=view2Minimum)]|
これが私がテストしたコードです:
NSView *view1 = [[NSTextView alloc] initWithFrame:NSZeroRect];
NSView *view2 = [[NSTextView alloc] initWithFrame:NSZeroRect];
[view1 setTranslatesAutoresizingMaskIntoConstraints:NO];
[view2 setTranslatesAutoresizingMaskIntoConstraints:NO];
NSView *contentView = [self.window contentView];
[contentView addSubview:view1];
[contentView addSubview:view2];
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(view1, view2);
[contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view1]|" options:NSLayoutConstraintOrientationVertical metrics:NULL views:viewsDictionary]];
[contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view2]|" options:NSLayoutConstraintOrientationVertical metrics:NULL views:viewsDictionary]];
NSDictionary *metrics = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat:300], @"view1SoftMinimum",
[NSNumber numberWithFloat:150], @"view1Minimum",
[NSNumber numberWithFloat:150], @"view2Minimum", nil];
[contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[view1(>=view1Minimum,>=view1SoftMinimum@480,==view2@479)]-[view2(>=view2Minimum)]|" options:0 metrics:metrics views:viewsDictionary]];