首先AppDelegate实现window的代理;
[plain]view plain copy print ? @interfaceAppDelegate:NSObject<NSApplicationDelegate,NSWindowDelegate>
接着将window的delegate链接到AppDelegate;
最后实现下面两端代码,如果实现了第一段代码,第二段代码就会失效:
1、完全退出程序
[plain]view plain copy print ? -(BOOL)windowShouldClose:(id)sender//closeboxquitstheapp { [NSAppterminate:self]; returnYES; }
2、隐藏后点击dock图标重新显示[plain]view plain copy print ? -(BOOL)applicationShouldHandleReopen:(NSApplication*)theApplicationhasVisibleWindows:(BOOL)flag { if(!flag){ [self.windowmakeKeyAndOrderFront:self]; returnYES; } returnNO; }
如果觉得《Mac点击关闭按钮退出程序 与 程序隐藏后点击dock图标重新显示》对你有帮助,请点赞、收藏,并留下你的观点哦!