设置 nsview 大小

发布于 2024-10-10 08:05:19 字数 773 浏览 1 评论 0原文

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

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];
}

提前致谢!

I'm working on the GUI of my application. I have a main view embedded into a NSScrollView. Its content is refreshed when the user clicks a button. It then determines the required height for displaying the content. The view is not displayed well, there are a lot of glitches, of items displayed twice... I know the problem is when I set the view size with [self setBounds: ...]. Do you know how I can change the view size? Here is code:

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];
}

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我一直都在从未离去 2024-10-17 08:05:19

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

Once again I found the solution. I was changing the nsview bounds inside the drawRect method (although it was before doing any drawing). I put that piece of code elsewhere and now it's perfectly working.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文