gpt4 book ai didi

cocoa - NSStackView 中的隐藏 View 未隐藏?

转载 作者:行者123 更新时间:2023-12-03 16:53:47 31 4
gpt4 key购买 nike

我创建了一个垂直的 NSStackView,其中包含两个 NSView 子类(它们只是绘制背景颜色的 NSView)。我将堆栈 View 设置为分离隐藏 View 。我已将其中一个 View 设置为隐藏。

这两个 View 都不会隐藏在堆栈 View 中。

为了确保我没有疯,我还设置了两个彼此相邻的相同 NSView,并隐藏了一个。果然,确实有人躲起来了。

堆栈 View 的分布设置为按比例填充(这似乎并不重要)。

在 IB 中,行为似乎是正确的;其中一个 View 隐藏。

我一定错过了一些非常明显的东西,对吧?

enter image description here

如果相关的话,NSView 子类: #import“ViewWithBackgroundColor.h”

@implementation ViewWithBackgroundColor

- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
[self.backgroundColor set];
[NSBezierPath fillRect:dirtyRect];
if(self.bottomBorderColor != nil) {
NSBezierPath *linePath = [[NSBezierPath alloc] init];
[self.bottomBorderColor set];
linePath.lineWidth = 2.0;
[linePath moveToPoint:NSMakePoint(0, 0)];
[linePath lineToPoint:NSMakePoint(dirtyRect.size.width, 0)];
[linePath stroke];
}

}

- (NSColor *) backgroundColor {
if (_backgroundColor) {
return _backgroundColor;
} else {
return [NSColor clearColor];
}
}

@end

最佳答案

这看起来像是 IB 和堆栈 View 的问题(如果尚未提交,请提交错误报告)。

要解决此问题,您可以:

  • 不要在IB中隐藏该按钮,并在运行时将其设置为隐藏。

  • 取消选中 IB 中的“分离隐藏 View ”堆栈 View 属性(在屏幕截图中可见),并在运行时使用 -[NSStackView setDetachesHiddenViews:] 设置它。

关于cocoa - NSStackView 中的隐藏 View 未隐藏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35308998/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com