Mac点击关闭按钮退出程序 与 程序隐藏后点击dock图标重新显示

首先AppDelegate实现window的代理;

[plain]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. @interface AppDelegate : NSObject <NSApplicationDelegate,NSWindowDelegate>  


接着将window的delegate链接到AppDelegate;

最后实现下面两端代码,如果实现了第一段代码,第二段代码就会失效:

1、完全退出程序

[plain]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. - (BOOL)windowShouldClose:(id)sender //close box quits the app  
  2. {  
  3.     [NSApp terminate:self];  
  4.     return YES;  
  5. }  

2、隐藏后点击dock图标重新显示

[plain]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag  
  2. {  
  3.     if (!flag){  
  4.         [self.window makeKeyAndOrderFront:self];  
  5.         return YES;   
  6.     }  
  7.     return NO;  
  8.       
  9. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值