osx - NSAnimation removes button background colour -


i working on mac app. trying simple animation makes nsbutton move down. animation works nicely, when it, background colour of nsbutton disappears reason. here code:

// tell view create backing layer. additionbutton.wantslayer = yes;  // set layer redraw policy. better done in // initialization method of 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]; 

button move down animation:

enter image description here

button after move down animation:

enter image description here

update 1

just make clear, not using background image in buttons. using background nscolor set in viewdidload method so:

[[additionbutton cell] setbackgroundcolor:[nscolor colorwithred:(100/255.0) green:(43/255.0) blue:(22/255.0) alpha:1.0]]; 

i presume appkit bug. there couple of ways can work around it.


workaround 1:

don't use layers. button you're animating seems small, , might able away using non layer-backed animation , still have decent. button redraw during each step of animation, animate correctly. means have do:

[nsanimationcontext runanimationgroup:^(nsanimationcontext *context) {               additionbutton.animator.frame = cgrectoffset(additionbutton.frame, 0, -20); } completionhandler:nil]; 

workaround 2:

set background color on layer.

additionbutton.wantslayer = yes; additionbutton.layer.backgroundcolor = nscolor.redcolor.cgcolor; additionbutton.layercontentsredrawpolicy = nsviewlayercontentsredrawonsetneedsdisplay;  [nsanimationcontext runanimationgroup:^(nsanimationcontext *context) {               additionbutton.animator.frame = cgrectoffset(additionbutton.frame, 0, -20); } completionhandler:nil]; 

workaround 3:

subclass nsbuttoncell, , implement -drawbezelwithframe:inview:, drawing background color there. keep in mind parent view containing button should layer-backed, otherwise button still redraw on every step.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -