2014-02-07 46 views
0

我在NSWindowController中提供了一個NSPanel。當我按下NSPanel標題欄的紅色小按鈕時,我想用不同的動畫改變它消失的方式。我怎麼做?有沒有像 - (void)closeButtonPressed,我可以改變。因爲NSWindow的 - (void)關閉不像我想要的那樣工作。當我提出它,我不喜歡這樣寫道:
當我單擊紅色關閉按鈕時,如何以及在哪裏可以更改關閉NSPanel的動畫?

[self.imagePanelController.previewPanel setFrame:NSRectFromCGRect(CGRectMake(self.window.frame.origin.x + self.window.frame.size.width/4 , self.window.frame.origin.y + self.bounds.size.height/4, self.ciImage.extent.size.width, self.ciImage.extent.size.height)) display:YES animate:YES]; 

我想重新設置一個新的框架和動態顯示,按下面板上的關閉按鈕時。有任何想法嗎?

+0

短渲染的東西成層和其動畫的,Windows系統有一個[動畫行爲(https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/ NSWindow_Class /參考/#的reference.html // apple_ref/OCC/instm/NSWindow/setAnimationBehavior :)。 – CodaFi

回答

0

所以我想出了自己,它適用於我,我不知道這是最好的解決方案,但確實是我所需要的。所以我只是發佈這個,如果有人正在尋找類似的東西。

我得到了NSPanel的closeButton,並執行了一個動作來關閉它的動畫來打開面板。

NSButton *closeButton = [self.imagePanelController.previewPanel standardWindowButton:NSWindowCloseButton]; 
    [closeButton setTarget:self]; 
    [closeButton setAction:@selector(closePanel)]; 

- (void)closePanel 
{ 

    int calcX = self.window.frame.size.width - self.bounds.size.width; 
    int x = self.window.frame.origin.x + calcX; 
    int y = self.window.frame.origin.y; 
    int width = self.bounds.size.width; 
    int height = self.bounds.size.height; 

    [self.imagePanelController.previewPanel setFrame:NSRectFromCGRect(CGRectMake(x, y, width, height)) display:YES animate:YES]; 
    [self.imagePanelController.previewPanel close]; 

} 
相關問題