Animated button
-
Hi everyone,
what is the simplest way to implement an animated button (the
animation should start as it is pressed)?
I've tried with a animated gif, unfortunately when pressed it doesn't
start the animation.
I'm thinking in the line of replacing the button image frame by frame
as it is pushed, would that be a way to go?
Any help appreciated. -
> I've tried with a animated gif, unfortunately when pressed it doesn't
> start the animation.
That's because NSButtonCell really doesn't have the ability to
animate an image on its own. The simplest setup is to use NSTimer to
periodically 'advance' the frame of your animation by setting a new
button image. Be reasonable with frame rate (ie, your timer interval),
though. :-)
--
I.S. -
Hi Micha,
I'd suggest core animation as the easiest route but i'm sort of partial.
HTH,
-bd-
http://bill.dudney.net/roller/objc
On Feb 26, 2008, at 8:37 AM, Micha Fuhrmann wrote:
> Hi everyone,
>
> what is the simplest way to implement an animated button (the
> animation should start as it is pressed)?
>
> I've tried with a animated gif, unfortunately when pressed it
> doesn't start the animation.
>
> I'm thinking in the line of replacing the button image frame by
> frame as it is pushed, would that be a way to go?
>
> Any help appreciated.
-
Hi Micha,
I'd suggest core animation as the easiest route but i'm sort of partial.
HTH,
-bd-
http://bill.dudney.net/roller/objc
On Feb 26, 2008, at 8:37 AM, Micha Fuhrmann wrote:
> Hi everyone,
>
> what is the simplest way to implement an animated button (the
> animation should start as it is pressed)?
>
> I've tried with a animated gif, unfortunately when pressed it
> doesn't start the animation.
>
> I'm thinking in the line of replacing the button image frame by
> frame as it is pushed, would that be a way to go?
>
> Any help appreciated.
-
> I'd suggest core animation as the easiest route but i'm sort of partial.
For my own enlightenment, can you outline generally how this would
be accomplished with Core Animation? I'm very interested.
--
I.S. -
Hi,
Sure...
Make 2 layers one is the 'background' the other is the button (think
the 'on/off' switch in time machine prefs pane)
when the user clicks the button you switch it to the on or off
position with buttonLayer.position = oppositePosition (a CGPoint)
make sense?
If not please feel free to ping and I'd be glad to elaborate.
TTFN,
-bd-
http://bill.dudney.net/roller/objc
On Feb 26, 2008, at 11:49 AM, I. Savant wrote:
>> I'd suggest core animation as the easiest route but i'm sort of
>> partial.
>
> For my own enlightenment, can you outline generally how this would
> be accomplished with Core Animation? I'm very interested.
>
> --
> I.S.
-
Or, if you had a sequence of CGImages you wanted to show in a loop,
you could do this to kick off the animation.
CAKeyframeAnimation *animation = [CAKeyframeAnimation
animationWithKeyPath:@"contents"];
animation.calculationMode = kCAAnimationDiscrete;
animation.values = arrayOfCGImageFrames;
animation.duration = PERIOD;
animation.repeatCount = FLT_MAX;
[[self layer] addAnimation:animation forKey:@"MyAnimation"];
-Ken
On Tue, Feb 26, 2008 at 3:50 PM, Bill Dudney <bdudney...> wrote:
> Hi,
>
> Sure...
>
> Make 2 layers one is the 'background' the other is the button (think
> the 'on/off' switch in time machine prefs pane)
> when the user clicks the button you switch it to the on or off
> position with buttonLayer.position = oppositePosition (a CGPoint)
>
> make sense?
>
> If not please feel free to ping and I'd be glad to elaborate.
>
> TTFN,
>
>
>
> -bd-
> http://bill.dudney.net/roller/objc
>
>
>
> On Feb 26, 2008, at 11:49 AM, I. Savant wrote:
>
>>> I'd suggest core animation as the easiest route but i'm sort of
>>> partial.
>>
>> For my own enlightenment, can you outline generally how this would
>> be accomplished with Core Animation? I'm very interested.
>>
>> --
>> I.S.
>
-
On Feb 26, 2008, at 1:49 PM, I. Savant wrote:
>> I'd suggest core animation as the easiest route but i'm sort of
>> partial.
>
> For my own enlightenment, can you outline generally how this would
> be accomplished with Core Animation? I'm very interested.
The Core Animation Programming guide has some sample code that might
be of value:
<http://developer.apple.com/documentation/Cocoa/Conceptual/CoreAnimation_gui
de/Articles/AnimatingLayers.html#//apple_ref/doc/uid/TP40006085-SW1>
This code shows how to build an explicit animation that will create
"pulsing" effect.
later,
douglas -
> The Core Animation Programming guide has some sample code that might
> be of value:
>
> <http://developer.apple.com/documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/AnimatingLayers.html#//apple_ref/doc/uid/TP40006085-SW1
It's a great example, Douglas, but I think the OP needs to clarify
the nature of the animation he's trying to achieve. Micah, you
mentioned you had an animated gif. Can you post it somewhere
(attachments are filtered on-list, so post it to a web site / file
hosting service)? If you already have "frames" of an existing
animation that's easier to use than programmatically using Core Image
filters, etc. then this example doesn't directly answer your question
(AFAIK, that is).
--
I.S.



