自动调整 NSView 大小
我正在用可可做一些事情,我认为这对于像我这样的初学者来说有点复杂。我尝试了一些东西,但我承认我首先需要一些理论,因为我想准确理解这些概念的含义。
我看到每个 NSView 及其子类都有一个称为 frame
的东西,还有一个称为 bounds
的东西。它们都有一个带有宽度和高度的尺寸以及一个原点。
我有一个 NSView ,里面有一个 NSTableView 。 我有表视图中一行的大小,我想将 NSView 和 NSTableView 的高度设置为等于 rows*rowSize ,这样 NSView+subviews 组就会自动调整大小当向表视图的数据源添加或删除对象时。
我做了一些实验,但最终我对框架、边界、大小等感到有点困惑。我不知道我应该改变什么以及如何改变。
您能否给我一些关于边界和框架的基本含义的提示,以及如何实现神奇的大小调整?
感谢您提前的回复。最好的问候,
-阿尔贝
I'm doing something with cocoa which I think is a bit complicate for a beginner like me. I tried a few things, but I admit I need some theory first, because I would like to understand exactly the meaning of this concepts.
I see that every NSView and every class that subclasses it has one thing called frame
, and one called bounds
. They both have a size with width and height and an origin.
I have an NSView with an NSTableView inside of it.
I have the size of a row from the table view, and I would like to set the height of both NSView and NSTableView equal to rows*rowSize
, in a way that the group NSView+subviews is automatically resized when an object is added or removed to and from the data source of the Table View.
I made some experiments, but I did end a bit confused about frame, bounds, sizes and so on. I don't know what I should change and how.
Can you please give me an hint about what bounds and frame basically are, and how can I achieve that magic resizing?
Thank you for your replies in advance. Best regards,
—Albé
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
框架和边界之间的区别在查看编程指南(在查看几何图形下)。
您还需要仔细阅读 NSView 类参考,您可以在其中找到一些方便的通知,例如
NSViewFrameDidChangeNotification
和方便的方法,例如setPostsFrameChangedNotifications:
。The difference between frame and bounds is covered very nicely in the View Programming Guide (under View Geometry).
You'll also want to peruse the NSView Class Reference, where you'll find some handy notifications, such as
NSViewFrameDidChangeNotification
and handy methods such assetPostsFrameChangedNotifications:
.