我在Mac應用程序的工作。我試圖做一個簡單的動畫,使NSButton向下移動。動畫效果非常好,但是當我這樣做時,我的NSButton的背景顏色由於某種原因而消失。這裏是我的代碼:NSAnimation刪除按鈕的背景顏色
// Tell the view to create a backing layer.
additionButton.wantsLayer = YES;
// Set the layer redraw policy. This would be better done in
// the initialization method of a NSView subclass instead of here.
additionButton.layerContentsRedrawPolicy = NSViewLayerContentsRedrawOnSetNeedsDisplay;
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
context.duration = 1.0f;
additionButton.animator.frame = CGRectOffset(additionButton.frame, 0.0, -20.0);
//additionButton.frame = CGRectOffset(additionButton.frame, 0.0, -20.0);
} completionHandler:nil];
按鈕向下移動的動畫:
按鈕移動後向下動畫:
更新1
只是爲了說清楚,我沒有在按鈕中使用背景圖片。我使用的是背景NSColor我在viewDidLoad方法設置像這樣:
[[additionButton cell] setBackgroundColor:[NSColor colorWithRed:(100/255.0) green:(43/255.0) blue:(22/255.0) alpha:1.0]];
的圖像不顯示 – 2015-04-01 05:58:15
@ysaditya但我不使用圖片爲我NSButton的背景。我用一個簡單的NSColor填充了它。 – Supertecnoboff 2015-04-01 05:59:24
你正在使用哪種按鈕類型(例如瞬時推入等) – 2015-04-01 06:09:17