Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
cocoa--使嵌套的NSView和Calayer按比例调整大小_Cocoa_Calayer_Nsview_Resize_Autoresizingmask - Fatal编程技术网

cocoa--使嵌套的NSView和Calayer按比例调整大小

cocoa--使嵌套的NSView和Calayer按比例调整大小,cocoa,calayer,nsview,resize,autoresizingmask,Cocoa,Calayer,Nsview,Resize,Autoresizingmask,我的NSWindow的contentView是NSView子类。它还有一些其他NSView子类作为子视图。子视图是基于图层的,这些图层依次包含子图层。一些子层具有更多的子层 我希望在调整窗口大小时,整个窗口都能按比例调整大小。什么是正确的方式来设置它,以便实现这一点 谢谢 编辑:我根本没有使用Interface Builder。以下是我在调整父窗口大小时,为使NSView的内容按比例缩放所做的工作。首先,在interface builder中,我将NSView添加到窗口中,然后在AppDeleg

我的NSWindow的contentView是NSView子类。它还有一些其他NSView子类作为子视图。子视图是基于图层的,这些图层依次包含子图层。一些子层具有更多的子层

我希望在调整窗口大小时,整个窗口都能按比例调整大小。什么是正确的方式来设置它,以便实现这一点

谢谢


编辑:我根本没有使用Interface Builder。

以下是我在调整父窗口大小时,为使NSView的内容按比例缩放所做的工作。首先,在interface builder中,我将NSView添加到窗口中,然后在AppDelegate中添加对它的引用。我的恰巧被称为
scrollView
。我从
滚动视图中删除了所有自动调整大小的行为

然后,我在AppDelegate中添加了以下内容:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // keep the aspect ratio constant so that the content looks good
    [window setContentAspectRatio:NSMakeSize(2, 1)];
    window.delegate = self;
}

- (void)windowDidResize:(NSNotification *)notification {
    // size the scrollView to fill the window, but keep its bounds constant
    NSRect rect = [[window contentView] frame];
    NSRect oldBounds = [scrollView bounds];
    [scrollView setFrame:rect];
    [scrollView setBounds:oldBounds];
}

这也将AppDelegate转换为窗口委托。很好,因为我没有太多的逻辑。通过在更改帧时保持边界不变,将平滑地缩小
scrollView
的内容。

文档建议,设置视图边界将使其在帧更改时保持不变。理论上,如果边界不变,则当帧发生变化时,内容将通过变换进行渲染。但我还没有想出如何让边界保持固定。是否有任何方法可以
为NSView本身设置ContentAspectRatio