私は初めてNSLayoutConstraintです。
NSScrollViewのコンテンツをプログラムで管理したい。最後に、私がやりたいことは、他のメソッドの後に追加し、必要に応じて のを拡大するNSScrollViewメソッドを使用して のサブクラスを作成することです。- add:(NSView *)aViewaViewdocumentViewNSScrollView
(これはすべてOSX用です)存在すると思いますが、見つからないので、誰かがこれを見つける場所を知っていれば、私はいます;)理解するのに役立つ写真があります:

これを行う私の計画は、NSLayoutConstraints を使用することです。制約は次のとおりです。
view 1、view 2、などの間の垂直方向のスペースを均等にします。- 高さは、、 などの
documentView高さの合計に適応する必要があります。view 1view 2 documentViewandview 1と last の間のいくつかの固定された垂直マージンview。view 1、view 2などは右寄せ
それで、私の質問に行きましょう:私はただ追加することから始めましたview 1(残りは後で見ていきます)。私は次のことをしました:
theScrollView私のNSScrollViewです。newSubview追加したいビューです。画像に関しては、中古品ですview 1。theContainer = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)] ; [theScrollView setDocumentView:theContainer] ; [newSubview setTranslatesAutoresizingMaskIntoConstraints:NO]; [theContainer addSubview:newSubview] ; NSLog(@"superview ? %@", [newSubview superview]) ; NSLog(@"view ? %@", newSubview) ; NSLog(@"NSScrollView ? %@", self) ; NSLog(@"NSScrollView content ? %@", self.contentView) ; NSArray * arrayOfConst1 ; arrayOfConst1 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-50-[newSubview]" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(newSubview)]; NSLog(@"First constraints : %@", arrayOfConst1) ; NSArray * arrayOfConst2 ; arrayOfConst2 = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[newSubview]" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(newSubview)]; NSLog(@"Second constraints : %@", arrayOfConst2) ; [newSubview removeConstraints:[newSubview constraints]] ; [theContainer removeConstraints:[theContainer constraints]] ; [theContainer addConstraints:arrayOfConst1] ; [theContainer addConstraints:arrayOfConst2] ; NSLog(@"Frame of theContainer : %@", NSStringFromRect(theContainer.frame));
でも、うまくいかず、フレームのtheContainerまま(0,0,0,0)。
私は初めてNSLayoutConstraintsです; 私が欠けているものは何ですか?