我正在使用OS X的應用程序,在該應用程序中使用自定義窗口來繪製圖像作爲背景(包括標題欄)。我一直在修改this code以繪製窗口,然後調用[NSWindow standardWindowButton:forStyleMask:]以獲得標準關閉,最小化和最大化按鈕。覆蓋NSWindow關閉按鈕
問題是我的應用程序使用NSPopovers,當彈出窗口打開時關閉或最小化應用程序時,它將關閉彈出窗口或顯示彈出窗口的動畫而不是關閉應用程序。有沒有方法可以覆蓋NSWindow中的默認關閉/最小化行爲,以便我可以先關閉任何打開的彈出窗口?
謝謝,如果這是一個明顯的問題,很抱歉 - 這是我第一次使用OS X SDK,所以我沒有太多的經驗。
編輯:我張貼這種幾個小時後,我想我有一個顯而易見的解決方案 - 使用NSWindowDelegate方法「windowWillClose:」和「windowWillMiniaturize:」和罷免popovers那裏。但是,由於關閉/最小化按鈕正在關閉彈出窗口,所以如果彈出窗口打開,這些委託方法將不會被調用。這讓我回到第1步,但希望知道這種行爲將有助於人們找出問題所在。
NSPopovers還存在另一個問題,我不知道它是否連接,所以我想我會在這裏添加它以防萬一有一個共同的原因。有時,當我試圖解散popover時,我會得到這個錯誤(對於上下文,我按下一個NSButton調用一個檢查popover是否存在的函數,如果存在,則關閉它):
2011-08-30 11:24:08.949 Playground[11194:707] *** Assertion failure in +[NSView _findFirstKeyViewInDirection:forKeyLoopGroupingView:], /SourceCache/AppKit/AppKit-1138/AppKit.subproj/NSView.m:11026
2011-08-30 11:24:08.950 Playground[11194:707] this method is supposed to only be invoked on top level items
2011-08-30 11:24:08.958 Playground[11194:707] (
0 CoreFoundation 0x00007fff873d4986 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff87ac6d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff873d47ba +[NSException raise:format:arguments:] + 106
3 Foundation 0x00007fff8950314f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 169
4 AppKit 0x00007fff88211064 +[NSView _findFirstKeyViewInDirection:forKeyLoopGroupingView:] + 137
5 AppKit 0x00007fff87d1f546 _replacementKeyViewAlongKeyViewPath + 565
6 AppKit 0x00007fff87d1f2ff -[NSView nextValidKeyView] + 179
7 AppKit 0x00007fff87d1f199 -[NSWindow _selectFirstKeyView] + 714
8 AppKit 0x00007fff882361cf _NSWindowRecursiveFindFirstResponder + 164
9 AppKit 0x00007fff882395c8 _NSWindowExchange + 79
10 AppKit 0x00007fff883a7e3a -[_NSWindowTransformAnimation startAnimation] + 426
11 AppKit 0x00007fff87c98bb2 -[NSWindow _doOrderWindow:relativeTo:findKey:forCounter:force:isModal:] + 592
12 AppKit 0x00007fff87c9890f -[NSWindow orderWindow:relativeTo:] + 154
13 AppKit 0x00007fff883dfaf0 _NSPopoverCloseAndAnimate + 948
14 Playground 0x00000001000078a4 -[MainWindowController dismissPopover:] + 100
15 Playgorund 0x0000000100007012 -[MainWindowController requestWasClicked:] + 98
16 CoreFoundation 0x00007fff873c411d -[NSObject performSelector:withObject:] + 61
17 AppKit 0x00007fff87ca2852 -[NSApplication sendAction:to:from:] + 139
18 AppKit 0x00007fff87ca2784 -[NSControl sendAction:to:] + 88
19 AppKit 0x00007fff87ca26af -[NSCell _sendActionFrom:] + 137
20 AppKit 0x00007fff87ca1b7a -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2014
21 AppKit 0x00007fff87d2157c -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 489
22 AppKit 0x00007fff87ca0786 -[NSControl mouseDown:] + 786
23 AppKit 0x00007fff87c6b66e -[NSWindow sendEvent:] + 6280
24 AppKit 0x00007fff87c03f19 -[NSApplication sendEvent:] + 5665
25 AppKit 0x00007fff87b9a42b -[NSApplication run] + 548
26 AppKit 0x00007fff87e1852a NSApplicationMain + 867
27 Playground 0x0000000100001c52 main + 34
28 Playground 0x0000000100001c24 start + 52
29 ??? 0x0000000000000001 0x0 + 1
)
但是...怎麼樣的堆棧跟蹤?!我需要知道。 –
@ Big-OClaire不幸的是,這個問題已經接近6歲了,我實際上無法再訪問源代碼,所以我不能幫你。抱歉! – Aaron