当滚动条出现/消失时如何调整 NSOutlineView 列的大小?

发布于 2024-08-23 06:00:19 字数 718 浏览 3 评论 0原文

这应该是非常基本的,但尝试了一个小时左右后,我无法弄清楚如何正确执行此操作:

我有一个包含两列的 NSOutline 视图,其中正确的一列应该始终完全可见。封闭的 NSScrollView 设置为仅显示垂直滚动条。现在,每当垂直滚动条出现时,它都会覆盖右列的一部分。然而,我想要实现的是右栏向左移动,以便它仍然完全可见。

我首先尝试摆弄 IB 中的调整大小选项一段时间,但这似乎没有成功。

然后我创建了一个自定义 NSOutlineView ,

-(void)viewWillDraw {
 CGRect contentFrame = [[[self enclosingScrollView] contentView] frame];
 CGRect ourFrame = self.frame;

 CGFloat correction = ourFrame.size.width - contentFrame.size.width;

 //resize the first column when the scrollbar appears 
 [[self outlineTableColumn] setWidth:kOutlineColumnWidth - correction];

 [super viewWillDraw];
}

问题是,当滚动条消失并且列由于某种原因增大和缩小几次时,该函数会被调用几次,这非常难看。此外,当窗口失去焦点时,左列会恢复到正常大小,导致右列再次被滚动条覆盖。

This ought to be very basic but after trying for an hour or so I can't figure out how to do this correctly:

I have a NSOutline view with two columns, of which the right one should always be fully visible. The enclosing NSScrollView is set to show a vertical scroller only. Now whenever the vertical scroller appears it covers part of the right column. What I would like to achieve however, is that the right column moves left so that it's still fully visible.

I've first tried fiddling with the resizing options in IB for a while but this didn't seem to do the trick.

I've then created a custom NSOutlineView with

-(void)viewWillDraw {
 CGRect contentFrame = [[[self enclosingScrollView] contentView] frame];
 CGRect ourFrame = self.frame;

 CGFloat correction = ourFrame.size.width - contentFrame.size.width;

 //resize the first column when the scrollbar appears 
 [[self outlineTableColumn] setWidth:kOutlineColumnWidth - correction];

 [super viewWillDraw];
}

Problem is, the function gets called several times when the scroller disappears and the column grows and shrinks a few times for some reason which is pretty ugly. Also when the window loses focus, the left column grows back to normal size causing the right column to be covered by the scroller again.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文