以编程方式设置NSWindow Size [英] Set NSWindow Size programmatically

查看:85
本文介绍了以编程方式设置NSWindow Size的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过编程方式设置窗口大小?我在IB中有一个窗口,我想在代码中设置它的大小以放大它.

How can I set the window size programmatically? I have a window in IB and I want to set the size of it in my code to make it larger.

推荐答案

使用-setFrame:display:animate:进行最大程度的控制:

Use -setFrame:display:animate: for maximum control:

NSRect frame = [window frame];
frame.size = theSizeYouWant;
[window setFrame: frame display: YES animate: whetherYouWantAnimation];

请注意,窗口坐标是从您惯常使用的位置翻转过来的.矩形的原点位于OS X上的Quartz/Cocoa中的左下角.要确保原点不变:

Note that window coordinates are flipped from what you might be used to. The origin point of a rectangle is at its bottom left in Quartz/Cocoa on OS X. To ensure the origin point remains the same:

NSRect frame = [window frame];
frame.origin.y -= frame.size.height; // remove the old height
frame.origin.y += theSizeYouWant.height; // add the new height
frame.size = theSizeYouWant;
// continue as before

这篇关于以编程方式设置NSWindow Size的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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