私はMacアプリに取り組んでいます。NSButton を下に移動させる簡単なアニメーションを実行しようとしています。アニメーションは非常にうまく機能しますが、それを行うと、何らかの理由で NSButton の背景色が消えます。これが私のコードです:
// 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
明確にするために、ボタンに背景画像を使用していません。次のように viewDidLoad メソッドで設定した背景 NSColor を使用しています。
[[additionButton cell] setBackgroundColor:[NSColor colorWithRed:(100/255.0) green:(43/255.0) blue:(22/255.0) alpha:1.0]];