cocoa——让嵌套的 NSView 和 CALayers 按比例调整大小
我的 NSWindow 的 contentView 是 NSView 子类。它还有一些其他 NSView 子类作为子视图。子视图是基于图层的,而这些图层又包含子图层。一些子层具有另外的子子层。
我希望在调整窗口大小时,整个内容也按比例调整大小。正确的设置方法是什么?
谢谢
编辑:我根本不使用 Interface Builder。
My NSWindow's contentView is an NSView subclass. It has some other NSView subclasses as subviews. The subviews are layer-based, and those layers in turn contain sublayers. Some of the sublayers have further sub-sublayers.
I want the whole thing to resize proportionally when the window is resized. What is the right way to set it up so that will happen?
Thanks
EDIT: I am not using Interface Builder at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是我为使 NSView 的内容在调整父窗口大小时按比例缩放所做的工作。首先,在界面生成器中,我将 NSView 添加到窗口,然后在 AppDelegate 中添加对它的引用。我的恰好叫做
scrollView
。我从scrollView
中删除了所有自动调整大小的行为。然后,在我的 AppDelegate 中添加了以下内容:
这也将 AppDelegate 变成了窗口委托。好吧,因为我没有太多逻辑。通过在更改框架时保持边界不变,
scrollView
的内容将平滑缩小。Here's what I've done to get the contents of an NSView to scale proportionally as I resize the parent window. First, in interface builder, I added my NSView to the window, then added a reference to it in my AppDelegate. Mine happens to be called
scrollView
. I removed all of the auto-sizing behaviour from thescrollView
.Then, in my AppDelegate I added this:
This turns the AppDelegate into the window delegate too. Fine since I've not got much logic in it. By keeping the bounds constant while changing the frame, the contents of
scrollView
will be scaled down smoothly.