考虑到NSWindow
的新尺寸,您如何调整contentView
的尺寸?
答案 0 :(得分:4)
- (void) resizeWindowWithContentSize:(NSSize)contentSize animated:(BOOL)animated {
CGFloat titleBarHeight = self.window.frame.size.height - ((NSView*)self.window.contentView).frame.size.height;
CGSize windowSize = CGSizeMake(contentSize.width, contentSize.height + titleBarHeight);
// Optional: keep it centered
float originX = self.window.frame.origin.x + (self.window.frame.size.width - windowSize.width) / 2;
float originY = self.window.frame.origin.y + (self.window.frame.size.height - windowSize.height) / 2;
NSRect windowFrame = CGRectMake(originX, originY, windowSize.width, windowSize.height);
[self.window setFrame:windowFrame display:YES animate:animated];
}
答案 1 :(得分:2)
你可以做 -
[window setContentSize:newContentSize]
还有一些方法可以在窗口和内容大小之间进行转换:
- (NSRect)contentRectForFrameRect:(NSRect)windowFrame
- (NSRect)frameRectForContentRect:(NSRect)windowContent