我是靠谱客的博主 魔幻小兔子,最近开发中收集的这篇文章主要介绍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.

最后

以上就是魔幻小兔子为你收集整理的setaspectratio函数_在调整窗口大小之前,setAspectRatio不起作用的全部内容,希望文章能够帮你解决setaspectratio函数_在调整窗口大小之前,setAspectRatio不起作用所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(65)

评论列表共有 0 条评论

立即
投稿
返回
顶部