当滚动条出现/消失时如何调整 NSOutlineView 列的大小?
这应该是非常基本的,但尝试了一个小时左右后,我无法弄清楚如何正确执行此操作:
我有一个包含两列的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论