如何在Dock显示或隐藏时获取事件?
答案 0 :(得分:1)
如果底座可见或不使用Carbon,您可以收到通知。我不知道在Cocoa中有什么办法。
(我没有测试过这个;它来自代码here)
创建回调方法:
#import <Carbon/Carbon.h>
static const EventTypeSpec appEvents[] = {
{ kEventClassApplication, kEventAppSystemUIModeChanged }
};
OSStatus DockChangedHandler(EventHandlerCallRef inCallRef, EventRef event, void *userData) {
OSStatus status = eventNotHandledErr;
switch(GetEventClass(event)) {
case kEventClassApplication: {
SystemUIMode *outMode;
SystemUIOptions *outOptions;
GetSystemUIMode(outMode, outOptions);
status = noErr;
}
break;
default:
return;
}
/*Insert whatever you want to do when you're notified of a dock change*/
return status;
}
然后将其放在您想要开始收听通知的任何地方:
InstallApplicationEventHandler(NewEventHandlerUPP(DockChangedHandler), GetEventTypeCount(appEvents), appEvents, 0, NULL);
更多信息:http://developer.apple.com/library/mac/#technotes/tn2002/tn2062.html