星五博客

mac中点击dock恢复app ui

至于点击dock恢复app ui,需要用kvc实现,具体如下:

AppDelegate中定义个属性

@property NSWindow *customKeyWindow; 

然后

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    self.customKeyWindow=[[NSWindow alloc]init];
    self.customKeyWindow=
	[(NSApplication*)aNotification.object valueForKey:@"_keyWindow"];
} 

重写代理

- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication
                    hasVisibleWindows:(BOOL)flag{
    //    NSLog(@"ddd");
    if (!flag){
        [self.customKeyWindow makeKeyAndOrderFront:nil];
    }
    return YES;
}


IOS