开发者

How to move an NSWindow without moving child NSWindows

开发者 https://www.devze.com 2023-04-10 13:30 出处:网络
I have a main window that is the center of my application. For different functions I open a child window to handle certain specialized functions. I want all of the windows to move independently, but r

I have a main window that is the center of my application. For different functions I open a child window to handle certain specialized functions. I want all of the windows to move independently, but right now if I 开发者_运维知识库move the original, central window then all of those child windows move with it. How can I make the child windows disconnected so they don't move with the parent?


Remove children temporarily before the window is moved, then put them back:

- (void)windowWillMove:(NSNotification *)notification;
{
    [window removeChildWindow:child];
}

- (void)windowDidMove:(NSNotification *)notification
{
    if (![window inLiveResize])
            [window addChildWindow:child ordered:NSWindowAbove];
}

Or, if you don't need NSWindowAbove ordering, just don't make them child in the first place :)


Another way you can show your child window without adding it as a child window, but achieve the same behavior within window' level:

[self.childWindowController showWindow:self];
[self.childWindowController.window setLevel:NSSubmenuWindowLevel];

I'm not sure is this method is correct and good solution, but it works for me.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号