gpt4 book ai didi

cocoa - 设置 nsview 大小

转载 作者:行者123 更新时间:2023-12-03 17:26:10 31 4
gpt4 key购买 nike

我正在开发我的应用程序的 GUI。我有一个嵌入到 NSScrollView 中的主视图。当用户单击按钮时,其内容会刷新。然后,它确定显示内容所需的高度。 View 显示得不好,有很多小故障,项目显示两次......我知道问题是当我使用 [self setBounds: ...] 设置 View 大小时。你知道如何更改 View 大小吗?这是代码:

CGFloat allHeight= 0.0;
for(int i=0; i < [publications count]; i++) {
Publication* pub= [publications objectAtIndex:i];
CGFloat pubHeight= [self heightForTextStorage:[pub statusContent] withWidth:300];
if (pubHeight < 100.0)
pubHeight= 100.0;
allHeight += pubHeight;
}

if (allHeight > [[self superview] bounds].size.height) {
NSRect allBounds= self.frame;
allBounds.size.height= allHeight;
[self setFrame:allBounds];
}
else {
NSRect allBounds= [[self superview] bounds];
[self setFrame:allBounds];
}

提前致谢!

最佳答案

我再次找到了解决方案。我正在更改 drawRect 方法内的 nsview 边界(尽管这是在进行任何绘图之前)。我把这段代码放在其他地方,现在它可以正常工作了。

关于cocoa - 设置 nsview 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4579031/

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