读取 NSWindow 调整大小事件

发布于 2024-11-19 08:45:28 字数 169 浏览 8 评论 0原文

我想知道是否有人知道,当 NSWindow 调整大小时我该如何读取? 假设我在一个空窗口(按钮除外)中有一个按钮,然后用户从右下角调整窗口大小,现在我应该这样做,以便在调整窗口大小时按钮也调整大小。我知道如何调整按钮大小,我知道如何调整窗口大小,而且我知道很多东西,但我不知道如何在用户调整窗口大小时收到通知,有什么提示吗?

I was wondering if anyone knows, how do I read when NSWindow is being resized?
Let's imagine I have a button in an empty window (other than the button), then user resizes the window from the bottom right corner, now I should make it so that the button also resizes when the window is being resized. I know how to resize button, and I know how to resize a window, and I know lots of stuff, but I don't know how to get notificated when ever the user resizes the window, any tips?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

断桥再见 2024-11-26 08:45:28

您可以使用 -windowDidResize:委托方法?

Can you use the ‑windowDidResize: delegate method?

原来分手还会想你 2024-11-26 08:45:28

在 .m 文件的 nib 中唤醒,

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenResize) name:NSWindowDidResizeNotification object:nil];

现在编写并创建一个方法

(void)screenResize
{
    NSRect rect = Preloader.frame;
    rect = NSMakeRect(self.view.frame.origin.x+self.view.frame.size.width/2, self.view.frame.origin.y+self.view.frame.size.height/2, Preloader.frame.size.width, Preloader.frame.size.height);
    Preloader.frame = rect;
    NSLog(@"X = %f, Y = %f, W = %f, H= %f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
}

,当您退出该类时编写

    [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidResizeNotification object:nil];

in the awake from nib of your .m file write

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenResize) name:NSWindowDidResizeNotification object:nil];

and create a method now

(void)screenResize
{
    NSRect rect = Preloader.frame;
    rect = NSMakeRect(self.view.frame.origin.x+self.view.frame.size.width/2, self.view.frame.origin.y+self.view.frame.size.height/2, Preloader.frame.size.width, Preloader.frame.size.height);
    Preloader.frame = rect;
    NSLog(@"X = %f, Y = %f, W = %f, H= %f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
}

and when you get out of that class write

    [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidResizeNotification object:nil];
银河中√捞星星 2024-11-26 08:45:28

On Xcode 4.3 and later, use the autolayout to add constraints to the button, you can get very complex layouts without writing any line of code .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文