开发者

Hide a child window from parent window hide all app

开发者 https://www.devze.com 2022-12-27 18:53 出处:网络
I have 2 windows one is the header [mainWindow] (-setMovableByWindowBackground:YES) and the other is the content [secWindow], child of the header, the header have a button to hide the content.

I have 2 windows one is the header [mainWindow] (-setMovableByWindowBackground:YES) and the other is the content [secWindow], child of the header, the header have a button to hide the content.

[mainWindow addChildWindow:secWindow ordered:NSWindowBelow];
[mainWindow setMovableByWindowBackground:YES];

code to hide secWindow:

(IBAction) toggleSecondary: (id) sender;
{
if ([secWindow isVisible]) {
    [secWindow开发者_如何学Python orderOut:self];
} else {        
    [secWindow orderFront:self];
}
}

The problem is when a push the button, all app hide, Main and Sec windows and only need to hide the [secWindow].


Weel, I found a solution, I don't know if a correct way, but works for me. ^_^

//get the mainWindow cordinates
NSRect theFrame = [mainWindow frame];
NSPoint theOrigin = theFrame.origin;
NSPoint pSecWin = theFrame.origin;
//put secWin below mainWindow
pSecWin.y = theOrigin.y - secHeight;

(IBAction) toggleSecondary: (id) sender;
{
if ([secWindow isVisible]) {
    [mainWindow removeChildWindow:secWindow];
    [secWindow orderOut:self];
} else {  
    [secWindow setFrameOrigin:pSecWin];
    [mainWindow addChildWindow:secWindow ordered:NSWindowBelow];      
    [secWindow orderFront:self];
}
}

so thats it, thanks anyway

0

精彩评论

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