views:

32

answers:

1

Hey, trying to put a simple png sequence animation into my app. I have the first frame in place in IB, and the graphanimation outlet connected to it. There are 54 pngs in the sequence with names "Comp 1_0000.png" to "Comp 1_00053.png"

Here's my code.

 -(void)viewDidLoad{
 for (int i=0; i<53; i++) {
         graphanimation.animationImages = [NSArray arrayWithObjects:
                           [UIImage imageNamed:@"Comp 1_000%d.png",i]];
    }
    graphanimation.animationDuration = 1.00;
 graphanimation.animationRepeatCount = 1;
 [graphanimation startAnimating];
 [self.view addSubview:graphanimation];
    [super viewDidLoad];    
} 

I think something is wrong with the way I am referencing the image filenames with the i integer. Can someone help me sort this sucker out? Thanks!

+1  A: 

You can't pass a variable argument list and format arguments to [UIImage imageNamed:].

Try something like this perhaps?

...
NSMutableArray *array = [NSMutableArray arrayWithCapacity:54]
for (int i = 0; i < 54; ++i) {
  NSString *name = [NSString stringWithFormat:@"Comp 1_000%d.png",i];
  UIImage *image = [UIImage imageNamed:name];
  [array addObject:image];
}
graphAnimation.animationImages = array;
...
dmaclach
Thank you!!And just something I found out:The animation ends and reverts to displaying the first frame. To get it to display the last frame, you just change the UIImageView to the last frame image in Interface Builder.
Hippocrates