Resizing NSWindow beyond the dock

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 02:43:26

问题


I am trying to resize an NSWindow to a certain size:

NSRect frame = [_window frame];

frame.size.width = 1024;
frame.size.height = 768 + 42; // add 42 for window frame

[_window setFrame: frame display: YES];
[_window center];

The adjusted height is always clipped at the Mac OS X application dock so in my case the view inside the window height will not be 768 but 680. Is there a way to force it to resize beyond the dock?


回答1:


Fixed it by implementing a subclass to override constrainFrameRect:toScreen:

- (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
{
    return frameRect;
}

From the Mac Developer Library, NSWindow Class Reference, constrainFrameRect:toScreen:

If the window is resizable and the window’s height is greater than the screen height, the rectangle’s height is adjusted to fit within the screen as well. The rectangle’s width and horizontal location are unaffected. You shouldn’t need to invoke this method yourself; it’s invoked automatically (and the modified frame is used to locate and set the size of the window) whenever a titled NSWindow object is placed onscreen and whenever its size is changed. Subclasses can override this method to prevent their instances from being constrained or to constrain them differently.



来源:https://stackoverflow.com/questions/17274610/resizing-nswindow-beyond-the-dock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!