How to Animate an image of NSButton?

PreranaPrerana INMember ✭✭

I have a button whose image changes into busy icon image when the button is clicked.Now some processing is done when it is clicked then depending on response, the image of button changes to a check mark or otherwise accordingly.

Now the busy icon shown during processing does not rotate (as button images don't have Animates property like ImageView has by default).

How can I animate the image of a button?

Any help would be really appreciated.

Thanks a ton in advance!!

Best Answers

  • SteveFlackSteveFlack GB ✭✭
    Accepted Answer

    AFAIK the animation of an NSImageView only animates things like GIF so that may not do what you want.

    Anyway, you're probably going to need a timer to animate whatever you animate. You could either use it to swap out the images in an NSButton (easy code but you'll need a lot of images) or you could do the rotation in core graphics. Personally I don't like NSButton/NSButtonCell much for this sort of thing and you may be better off swapping NSButton for a custom NSView that does the animation whilst the "button" is busy and then swapping it back when it's not.

  • SteveFlackSteveFlack GB ✭✭
    Accepted Answer

    Nope, there is no NSImageView...just an NSView that you animate in the Draw (drawRect in obj-c) method using a timer.

Answers

  • SteveFlackSteveFlack GBMember ✭✭
    Accepted Answer

    AFAIK the animation of an NSImageView only animates things like GIF so that may not do what you want.

    Anyway, you're probably going to need a timer to animate whatever you animate. You could either use it to swap out the images in an NSButton (easy code but you'll need a lot of images) or you could do the rotation in core graphics. Personally I don't like NSButton/NSButtonCell much for this sort of thing and you may be better off swapping NSButton for a custom NSView that does the animation whilst the "button" is busy and then swapping it back when it's not.

  • PreranaPrerana INMember ✭✭

    Hey @SteveFlack,

    Thanks a ton for your answer..The swapping of button for NSImageView was exactly the thing i was going to do, just wanted to confirm whether there was a easy way out to animate the NSButton image. I will go with the swapping approach.

    Thanks again..:)

  • SteveFlackSteveFlack GBMember ✭✭

    Bear in mind what I said about NSImageView. It animates GIFs (with all their limitations). Unless that's OK for what you want to do you would be better going to NSView not NSImageView and drawing the animation in that.

  • PreranaPrerana INMember ✭✭

    Ohhk.. @SteveFlack, Correct me if I am wrong..U saying I should have a NSView and in that NSImageView which I can animate, then swap this NSView with NSButton, right?

  • SteveFlackSteveFlack GBMember ✭✭
    Accepted Answer

    Nope, there is no NSImageView...just an NSView that you animate in the Draw (drawRect in obj-c) method using a timer.

  • PreranaPrerana INMember ✭✭

    Thanks @SteveFlack..I will keep in mind..:)

Sign In or Register to comment.