tags:

views:

80

answers:

2

hi , i want create image animation , i have 50 images with png format now i want set images name ... something like this but doesnt work !

my images name are : iamge_0000 to image_0050

pasheAnimation.animationImages  = [NSArray arrayWithObjects:
                                  [UIImage imageNamed:@"pashe_0000.png"],nil];

    [pasheAnimation setAnimationRepeatCount:5];
    pasheAnimation.animationDuration = 4;
    [pasheAnimation startAnimating];

??!?!?!?

jason Code [EDITED] :

NSMutableArray* myImages = [[[NSMutableArray alloc] initWithCapacity:607] autorelease];
    for( int i = 1; i <= 607; i++ ) {
        [myImages addObject:[UIImage imageNamed:[NSString stringWithFormat:@"p%d.png",i]]];
    }

    butterflyView.animationImages = myImages;
    [butterflyView setAnimationRepeatCount:100];
    butterflyView.animationDuration = 0;
    [butterflyView startAnimating];
+2  A: 
// There are actually 51 images in this series (0000-0050)     
NSMutableArray* myImages = [[[NSMutableArray alloc] initWithCapacity:51] autorelease];
for( int i = 0; i <= 50; i++ ) {
  [myImages addObject:[UIImage imageNamed:[NSString stringWithFormat:@"image_%04d.png", i]]?:[NSNull null]];
}
Jason Coco
-1: If the UIImage is nil this will throw an exception. Also, it should be %04, not %02, for a four-character length zero-padded decimal.
Alex Reynolds
@Alex Reynolds: I don't really know what your problem is with me, but I didn't vote you down, even though your answer was misleading.
Jason Coco
I don't have a problem with you, but your answer is wrong.
Alex Reynolds
@Alex Reynolds: It was a reference answer to his question, so I didn't do the error checking. Your answer simply silently ignores missing images. I'd argue that my answer would actually be better since it would be obvious that there is a programming error (missing images in the series), but it's updated anyway.
Jason Coco
Further, unless `myImages` gets a `release` somewhere, this will create a memory leak.
Alex Reynolds
Yes, he owns myImages. He will have to release them. This is a code snippet, not even a full function.
Jason Coco
It's misleading not to include the `release` message, since the OP is using the autoreleased `-arrayWithObjects:` method.
Alex Reynolds
@Alex Reynolds: Dude...
Jongsma
@Jongsma: What? If this chunk of code is used as-is, it will introduce a memory leak. Is that incorrect?
Alex Reynolds
No, Alex, it wouldn't. There is no context around this chunk of code, there is no closing scope so there is no memory leak. myImages is owned by whatever scope encloses it, and the regular memory management rules apply (meaning that it would have to be released or assigned to a variable with a larger scope). I added an autorelease just for you tho ;)
Jason Coco
Well, your answer was wrong ;) so thanks for fixing it!
Alex Reynolds
Thank you everybody ... iam a little bit amateur .i edited my post and write whole the animation code can you edit your code relate my animation code ? thank you
Momeks
Jason i edit my post according your code ! but doesn't work and crash !
Momeks
+1  A: 

You actually have 51 images, from zero to fifty.

NSMutableArray *myImages = [NSMutableArray arrayWithCapacity:51];
for (NSUInteger idx = 0; idx <= 50; idx++) {
    NSString *filename = [NSString stringWithFormat:"image_%04d.png", idx];
    UIImage *image = [UIImage imageNamed:filename];
    if (image) {
        [myImages addObject:image];
    }
    else {
        NSLog(@"Could not add %@", filename); // could also throw exception, if you want
    }
}
Alex Reynolds