setaspectratio函数_在调整窗口大小之前,setAspectRatio不起作用

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.

解决方案

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.

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.

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.

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值