いくつかのビュー (この例では NSTextField) を NSStackView に追加しようとしています:
NSStackView インスタンスを XIB ファイルに追加し、ウィジェットとしてアウトレットにDocumentにリンクしました。...didLoadNibで私はこれをやっています:
NSTextField *tf = [[NSTextField alloc] init];
tf.stringValue = @"124";
[tf setFrameSize:NSMakeSize(100, 20)];
[widgets addView:tf inGravity:NSStackViewGravityLeading];
NSLog(@"%f - %d", NSHeight(tf.frame), [tf hasAmbiguousLayout]);
NSTextField *tf2 = [[NSTextField alloc] init];
tf2.stringValue = @"123";
[tf2 setFrameSize:NSMakeSize(100, 20)];
[widgets addView:tf2 inGravity:NSStackViewGravityLeading];
NSLog(@"%f - %d", NSHeight(tf2.frame), [tf2 hasAmbiguousLayout]);
TextField は StackView に配置されますが、同じ位置に配置されます。つまり、2 番目のフィールドが最初に完全に重なります。[スペース+タブ]で最初に選択できます。
コンソール出力は次のとおりです。
2015-06-13 17:11:00.736 celty-test[62306:9217679] 20.000000 - 1
2015-06-13 17:11:00.739 celty-test[62306:9217679] Unable to simultaneously satisfy constraints:
(
"<NSLayoutConstraint:0x608000084bf0 V:[NSStackViewSpacer:0x6080001834d0(>=8)]>",
"<NSLayoutConstraint:0x608000084f10 V:[NSTextField:0x608000183330]-(0)-[NSStackViewSpacer:0x6080001834d0]>",
"<NSLayoutConstraint:0x608000085460 V:[NSStackViewSpacer:0x6080001834d0]-(0)-[NSTextField:0x608000183400]>",
"<NSAutoresizingMaskLayoutConstraint:0x608000084970 h=--& v=--& V:[NSTextField:0x608000183330]-(0)-| (Names: '|':NSStackViewContainer:0x6000001a0700 )>",
"<NSAutoresizingMaskLayoutConstraint:0x608000084d30 h=--& v=--& V:[NSTextField:0x608000183400]-(0)-| (Names: '|':NSStackViewContainer:0x6000001a0700 )>",
"<NSAutoresizingMaskLayoutConstraint:0x608000084d80 h=--& v=--& V:[NSTextField:0x608000183400(20)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x608000084bf0 V:[NSStackViewSpacer:0x6080001834d0(>=8)]>
Set the NSUserDefault NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints to YES to have -[NSWindow visualizeConstraints:] automatically called when this happens. And/or, break on objc_exception_throw to catch this in the debugger.
2015-06-13 17:11:00.802 celty-test[62306:9217679] Unable to simultaneously satisfy constraints:
(
"<NSLayoutConstraint:0x608000084f10 V:[NSTextField:0x608000183330]-(0)-[NSStackViewSpacer:0x6080001834d0]>",
"<NSLayoutConstraint:0x608000085460 V:[NSStackViewSpacer:0x6080001834d0]-(0)-[NSTextField:0x608000183400]>",
"<NSAutoresizingMaskLayoutConstraint:0x608000084970 h=--& v=--& V:[NSTextField:0x608000183330]-(0)-| (Names: '|':NSStackViewContainer:0x6000001a0700 )>",
"<NSAutoresizingMaskLayoutConstraint:0x608000084d30 h=--& v=--& V:[NSTextField:0x608000183400]-(0)-| (Names: '|':NSStackViewContainer:0x6000001a0700 )>",
"<NSAutoresizingMaskLayoutConstraint:0x608000084d80 h=--& v=--& V:[NSTextField:0x608000183400(20)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x608000085460 V:[NSStackViewSpacer:0x6080001834d0]-(0)-[NSTextField:0x608000183400]>
Set the NSUserDefault NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints to YES to have -[NSWindow visualizeConstraints:] automatically called when this happens. And/or, break on objc_exception_throw to catch this in the debugger.
2015-06-13 17:11:00.814 celty-test[62306:9217679] 20.000000 - 0
XIB と結果のスクリーンショット:
StackView に追加される制約はありません。StackView は垂直にする必要があります。スタックビューに動的な量のテキストフィールドが追加されます。