2011-02-19 87 views
7

我有一個NSWindow這是我從無形淡入到完全不透明,在自定義時間,使用動畫代理:可可 - 核心動畫 - 如何停止代理動畫?

[NSAnimationContext beginGrouping]; 
[[NSAnimationContext currentContext] setDuration:1.0f]; // Custom timing, 1 sec. 
[[myWindow animator] setAlphaValue: 1.0f]; 
[NSAnimationContext endGrouping]; 

但是,如果我嘗試設置窗口的可見性動畫正在進行,動畫不停止。在以下示例中,該窗口將短暫顯示爲0.5可見性,但會繼續生成動畫。

例如

[myWindow setAlphaValue: 0.5f]; // Animation continues after calling this. 

問:如何停止動畫?

謝謝。

回答

8

我有一個應用程序可以做到這一點(菜單欄覆蓋在Shroud窗口),並回答這個問題,我發現它的一個錯誤 - 雖然我的動畫是0.1s,所以它可能永遠不會在實踐中觸發。但是,謝謝。 :-)

0的動畫持續時間是特殊設置的,就像直接設置alpha值一樣,所以你不能使用它們,但是你可以使用一個非常短的持續時間,就像這樣,這將創建一個新動畫取代正在進行的動畫:

[NSAnimationContext beginGrouping]; 
[[NSAnimationContext currentContext] setDuration:0.01]; 
[[myWindow animator] setAlphaValue:0.5]; 
[NSAnimationContext endGrouping]; 
+0

謝謝尼古拉斯。是的,在發現0.0f不起作用之後,我剛剛得出了關於設置一個很短的持續時間的相同結論。乾杯。 – SirRatty 2011-02-19 03:48:34