【发布时间】:2012-09-25 06:02:18
【问题描述】:
我在使用新的自动布局功能时遇到问题。 我添加了一个名为 tableView 的 NSView 作为 workingBox 的子视图。 workingBox 还包含一些其他使用 Interface Builder 添加的子视图
[self.window setFrame:frame display:YES animate:YES];
[workingBox addSubview:tableView];
我的问题是,如果任何其他子视图触摸 tableView,那么它们将在动画中调整大小。不在添加 tableView 的位置附近的子视图保持正确的大小。我已经尝试在正在调整大小的子视图上设置 NSViewNotSizable resizeMask 但它不起作用。唯一有效的是将子视图向上移动(到错误的位置。
编辑:我在代码中添加了一个约束:
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(divider);
NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[divider(==1)]"
options:0
metrics:nil
views:viewsDictionary];
[workingBox addConstraints:constraints];
这使 NSView 保持在 1px 高度,但如果我将其锁定在顶部,它会阻止超级视图增长
【问题讨论】:
-
能否上传一张您描述的现象的图片并添加更多相关代码?
-
我认为关键是基于此:Suppose you drag a text field out of the library, snap it into the bottom left corner of a window, then drag-resize the right edge until it snaps into the bottom right corner. Nothing further is needed to specify that when the window is resized the text field should stretch horizontally 我猜我需要使用代码添加一个约束来覆盖基于 NSView 的定位添加的约束
标签: objective-c cocoa nsview autolayout