【发布时间】:2012-04-05 20:09:10
【问题描述】:
看来,当我在 mac 应用程序中发送一个窗口时:
NSRect frame = sender.window.frame;
NSLog(@"\nHeight and width of window frame: (%f,%f).\nThe x and y origin of the window frame: (%f,%f). ", frame.size.height, frame.size.width, frame.origin.x, frame.origin.y);
frame.origin.y -= 22;
frame.size.height += 22;
[sender.window setFrame:frame display:YES animate:NO];
虽然它看起来拉得更长,但没有一个 UI 元素(按钮)识别出窗口有更多空间。他们无法进入新开辟的空间。
我有几个按钮应该保留在窗口的按钮上,我将以下内容与上面的代码结合使用以将它们保持在一起:
CGRect quitBF = quitButton.frame;
quitBF.origin.y -= 5; // new y coordinate
quitButton.frame = quitBF;
CGRect loadBF = loadButton.frame;
loadBF.origin.y -= 5; // new y coordinate
loadButton.frame = loadBF;
CGRect saveBF = saveButton.frame;
saveBF.origin.y -= 5; // new y coordinate
saveButton.frame = saveBF;
CGRect resetBF = resetButton.frame;
resetBF.origin.y -= 5; // new y coordinate
resetButton.frame = resetBF;
然而,当它们到达窗口的旧尺寸时,它们开始消失。就连窗口也显得更长了。谢谢。
编辑:查看了窗口本身的自动调整大小。意识到问题与窗口内的 NSView 有关。该视图包含所有 UI 元素,并且它似乎在窗口更改时不会更改。现在唯一的问题是,我不知道如何从底部而不是从顶部扩展视图。 (增加顶部和移动原点不起作用,因为所有 UI 元素都随着 NSView 移动。
【问题讨论】:
-
我不认为问题出在您发布的这段代码中——我将它粘贴到一个项目中,它运行良好。窗口和按钮是否在 IB 中设置?
-
是的。所有这些都是在 IB 中首次设置的。
标签: objective-c user-interface window size resize