同时修改窗口框和视图框 [英] Simultaneously modify window frame and view frame

查看:184
本文介绍了同时修改窗口框和视图框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,用户可以按一个键在大窗口和小窗口之间切换。在小尺寸,窗口只是足够大,包含一定的视图。在大尺寸时,视图变得更大,保持其纵横比,使得视图最终与窗户一样高,但不是宽。在大尺寸时,视图需要在窗口中居中。

In my application the user can hit a key to toggle between a large and a small window size. At the small size, the window is just large enough to contain a certain view. At the large size, the view becomes larger, preserving its aspect ratio, so that the view ends up being as tall as the window but not as wide. At the large size, the view needs to be centered in the window.

现在我要做两个步骤:(1)调整窗口大小,(2)调整大小和移动视图。然而,用户可以看到这两个步骤发生一个接一个,而不是同时。有没有办法让它看起来像是NSWindow和NSView是同时调整大小/移动?还是用其他方法解决这个问题?

Right now I'm doing this in 2 steps: (1) resize the window, (2) resize and move the view. However, the user can see those 2 steps happening one after the other, instead of simultaneously. Is there a way to make it look as if the NSWindow and the NSView are being resized/moved simultaneously? Or some other way to solve this problem?

推荐答案

一个非常简单的方法是使用 NSWindow disableScreenUpdatesUntilFlush 。你可以这样使用它:

A very simple way to accomplish this is to use NSWindow disableScreenUpdatesUntilFlush. You would use it like this:

- (void) toggleWindowSize
{
    [ [ myView window ] disableScreenUpdatesUntilFlush ];

    // Do stuff to change the size of the window and view.
}

这篇关于同时修改窗口框和视图框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆