本文介绍了如何隐藏窗户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我添加了一个名为 NewWindow 的NSWindowController.现在,我想添加一个按钮来隐藏/查看wimdow.我的代码如下.

In my project,I added a extra NSWindowController namedNewWindow.Now I want add an button to hiden/view the wimdow.My code as following.

#import "AppDelegate.h"
#import "NewWindow.h"

@interface AppDelegate ()
@property (weak) IBOutlet NSView *view;
- (IBAction)showNewWindow:(id)sender;
@end
@implementation AppDelegate
{
 NewWindow *newWindow;
 BOOL isNewWindowLoad;
}
-(id)init
{
   self = [super init];
   if(self)
   {
      newWindow = [[NewWindow alloc] init];
   }
   return self;
}
- (IBAction)showNewWindow:(id)sender
{
   if(!isNewWindowLoad)
   {
     [newWindow loadWindow];
     isNewWindowsLoad = YES;
   }
   else
   {
     [[newWindow window] close];
     isNewWindowLoad = NO;
   }
}
@end

窗口可以加载,但不能隐藏.任何人都可以告诉我该怎么做?通过单击按钮来控制窗口的加载/隐藏.

the window can load,but it can't be hidden.Anyone can tell me how to do it?Through clicking the button to control the window load/hidden.

推荐答案

调用 orderOut 隐藏窗口.它仍然存在,您可以调用 orderFront makeKeyAndOrderFront 再次显示它.

Call orderOut to hide the window. It's still there, you can call orderFront or makeKeyAndOrderFront to show it again.

这篇关于如何隐藏窗户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 11:07