My Animated GIF is not (animated) ?

I want to display an animated GIF but only the first frame is displayed…
Here is some example code: in PB create a new Cocoa application project. Open the MainMenu.nib in Interface Builder, create a new subclass of NSWindowController named ImageWinController, instantiate it, connect it to the default window, put an NSImageView and a NSButton in the default window, add an IBOutlet named ibImage, connect it to the NSImageView and connect the button to a action named doRunAction, generates the source code the ImageWinController and go back in PB. Add the following instance variables to the ImageWinController class:
BOOL _running ;
NSTimer *_timer ;
int _frameCount, _currentFrame ;
NSBitmapImageRep *_imageRep ;
and here is the complete code of the controller class:
#import "ImageWinController.h"

@implementation ImageWinController

- (IBAction)doRunAction:(id)sender
_running = ([sender state]) ;

- (void)awakeFromNib
_running = NO ;
_timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(refresh:) userInfo:nil repeats:YES] ;

_imageRep = [[[[ibImage image] representations] objectAtIndex:0] retain] ;

_frameCount = [[_imageRep valueForProperty:NSImageFrameCount] intValue] ;
_currentFrame = [[_imageRep valueForProperty:NSImageCurrentFrame] intValue] ;


- (void)refresh:(NSTimer *)inTimer
if (_running) {
_currentFrame = (_currentFrame + 1) % _frameCount ;
[_imageRep setProperty:NSImageCurrentFrame withValue:[NSNumber numberWithInt:_currentFrame]] ;

NSImage *img = [[NSImage alloc] init] ;
[img addRepresentation:_imageRep] ;

[ibImage setImage:img] ;

Of course, adding error checking code will not hurt in a real world application…

Oct. 28, 2003
Panther update:
In Panther, NSImageView supports a new message:
[imageView setAnimates:YES]

You can also turn on animation for a NSImageView, directly in IB by checking the
Animates box.