the_majk
the_majk

Reputation: 23

How to [window setAspectRatio:size] to a x,y+92 format

I'm creating an OS X application, and I have a video player in a web view that covers 100% of the height and width of a window The player has 16:9 format, plus 92px in height for ads and player controls.

So I want to set the window's aspect ratio, so that when a user resizes the window, the aspect ratio of the video is maintained, including the extra 92px in height.

at the moment, I used;

[window setAspectRatio:window.frame.size];

But obviously that also proportionally adds to the 92px constant and thus alters the video player's aspect ratio.

Can someone help me out here?

Upvotes: 2

Views: 293

Answers (1)

jscs
jscs

Reputation: 64002

This is as simple as setting an object to be the window's delegate and implementing windowWillResize:toSize:. The window passes its proposed new size; the delegate can return a different size and the window will use that.

- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize 
{
    CGFloat newWidth = frameSize.width;
    CGFloat newHeight = ((newWidth / 16) * 9) + 92;

    return (NSSize){newWidth, newHeight};
}

Upvotes: 2

Related Questions