简体   繁体   English

如何停止使用自动版式调整NSView子视图的大小

[英]How do I stop an NSView subview being resized with Auto Layout

I am having a problem with the new Auto Layout functionality. 我对新的自动版式功能有疑问。 I add an NSView called tableView as a subview of workingBox. 我添加了一个名为tableView的NSView作为workingBox的子视图。 workingBox also contains some other subviews that were added with Interface Builder workingBox还包含随Interface Builder添加的其他一些子视图

[self.window setFrame:frame display:YES animate:YES];
[workingBox addSubview:tableView];

My problem is that if any of the other subviews touch tableView then they will get resized in the animation. 我的问题是,如果任何其他子视图触摸tableView,则它们将在动画中调整大小。 The subviews that are not near where tableView is being added remain the correct size. 不靠近要添加tableView的位置的子视图将保持正确的大小。 I have already tried setting NSViewNotSizable resizeMask on the subviews that are getting resized but it does not work. 我已经尝试在要调整大小的子视图上设置NSViewNotSizable resizeMask,但是它不起作用。 The only thing that works is moving the subview upwards (into the wrong position. 唯一有效的方法是将子视图向上移动(到错误的位置。


EDIT: I have added a constraint in code: 编辑:我在代码中添加了一个约束:

NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(divider);
NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[divider(==1)]"
                                                               options:0
                                                               metrics:nil
                                                                 views:viewsDictionary];
[workingBox addConstraints:constraints];  

This keeps the NSView at 1px height but if I lock it to the top it prevents the superview growing 这样可以将NSView保持在1px的高度,但是如果我将其锁定在顶部,则会阻止超级视图的增长

I could not make this work by adding a constraint in code. 我无法通过在代码中添加约束来完成这项工作。 However in Interface Builder I could see that there was a constraint for the NSView in question that was named 'Bottom Alignment'. 但是,在Interface Builder中,我可以看到存在问题的NSView约束被称为“底部对齐”。 I changed this to a priority of 1 in the inspector and it stopped the NSView getting stretched down when the window expanded. 我在检查器中将此优先级更改为1,并在窗口扩展时阻止了NSView拉伸。 I think this auto added constraint that I mentioned in my comment above had been the problem all along. 我认为我在上面的评论中提到的这种自动添加的约束一直都是问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM