ato*_*nda 17 size macos window objective-c nswindow
如何以编程方式设置窗口大小?我在IB中有一个窗口,我想在我的代码中设置它的大小以使其更大.
Jon*_*pan 28
使用-setFrame:display:animate:
的最大控制:
NSRect frame = [window frame];
frame.size = theSizeYouWant;
[window setFrame: frame display: YES animate: whetherYouWantAnimation];
Run Code Online (Sandbox Code Playgroud)
请注意,窗口坐标会从您可能习惯的位置翻转过来.矩形的原点位于OS X上的Quartz/Cocoa的左下角.为了确保原点保持不变:
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
Run Code Online (Sandbox Code Playgroud)
Leo*_*Leo 12
实际上似乎需要反转+/-以防止窗口在屏幕上移动:
NSRect frame = [window frame];
frame.origin.y += frame.size.height; // origin.y is top Y coordinate now
frame.origin.y -= theSizeYouWant.height; // new Y coordinate for the origin
frame.size = theSizeYouWant;
Run Code Online (Sandbox Code Playgroud)
迅捷版
var frame = self.view.window?.frame
frame?.size = NSSize(width: 400, height:200)
self.view.window?.setFrame(frame!, display: true)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
23543 次 |
最近记录: |