在调整窗口大小之前,setAspectRatio不起作用 [英] setAspectRatio doesn't work until the window is resized

查看:883
本文介绍了在调整窗口大小之前,setAspectRatio不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有一个主窗口,可在其中使用AVPlayer播放一些视频.为了强制使用特定的长宽比,我使用setAspectRatio:方法.我将其放置在应用程序的windowControllerDidLoadNib中:因此代码如下:

In my app I have a main window where I play some video using AVPlayer. In order to force a particular aspect ratio I'm using setAspectRatio: method. I placed it in my app's windowControllerDidLoadNib: so the code looks like:

- (void)windowControllerDidLoadNib:(NSWindowController *)windowController
{
   [super windowControllerDidLoadNib:windowController];

   // adjust the player aspect ratio
   [windowController.window setAspectRatio:NSMakeSize(1.85,1)];
   ...
   ...
}

问题在于,直到我调整窗口大小后,才可以设置此宽高比.

The problem is that this aspect ratio is not getting set until I resize the window.

有人知道这可能是什么问题吗? 任何帮助都将受到高度赞赏.

Does anyone know what the problem might be here? Any help is highly appreciated.

推荐答案

在调整窗口大小时,窗口的aspectRatio是一个约束*.所以,是的,直到用户尝试执行此操作才有效.

The aspectRatio of a window is a constraint* upon resizing of the window. So, yeah, it doesn't have any effect until the user tries to do that.

您需要将窗口的frame显式设置为尺寸具有该长宽比的矩形,并且您需要自己计算该矩形.

You need to explicitly set the window's frame to a rectangle whose size has that aspect ratio, and you will need to compute that rectangle yourself.

确保正确区分窗口的框架矩形,窗口的内容矩形(其大小与窗口的内容视图相同)和要播放的内容的大小.例如,您可能希望标题栏(属于框架的一部分)以该比例添加"1",而不是其中的一部分.

Make sure you properly distinguish between the window's frame rectangle, the window's content rectangle (which has the same size as the window's content view), and the size of the content you intend to play. For example, you probably want the title bar (which is part of the frame) to be in addition to the "1" in that ratio, not part of it.

*不是一般意义上的NSLayoutConstraint.

*Not in the NSLayoutConstraint sense, just the general sense.

这篇关于在调整窗口大小之前,setAspectRatio不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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