views:

443

answers:

1

Hi,

Ok, I have a button that, when pressed, should animate/play a png image sequence.

My problem is -

  • I press the button (button A) and the image sequence plays - which is good!
  • but then I press (button A) again and nothing happens. - bad.
  • but then... if I press (button A) a third time - the image sequence plays.

So basically, the image sequence only plays every second time I press the button?...I can't think what could be causing that?

Another scenario which might give you clues to the problem -

  • I press the button (button A) and everything works fine
  • I press a different button (button B) and it does its different thing
  • Then I press (button A) again and everything works fine.

So it seems, the image sequence only plays if something else happens in between (button A) presses?

Any ideas?

Here is the code... The views "viewDidLoad" has [self loadAnimX01];

    - (void) loadAnimX01 {

    x01 = [[UIImageView alloc] initWithFrame:CGRectMake(35.0f, 112.0f,70.0f, 115.0f)];
    NSMutableArray *array = [NSMutableArray array];
    for (int i = 1; i <= 15; i++) 
     [array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"pipe01_%02d.png",i]]];
    x01.animationImages = array;
    x01.animationDuration = 0.7;
    x01.animationRepeatCount = 1;
    [self.view addSubview:x01];
    [x01 release];
}

- (IBAction)pX01 {
    [x01 startAnimating];
}

Thanks!

+1  A: 

Well i figured out a solution. But I still cant make sense of it!?

  • I have to check to see if the sequence is playing
  • Then stop the sequence
  • Then play it.

This makes the the image sequence play every time I press the button

If anyone could tell my why my I have to do this... please let me know

Here is my solution

- (IBAction)pX01{
if ([x01 isAnimating]) { 
 [x01 stopAnimating];
}
[x01 startAnimating];

}

Thanks!

Jonathan
You should mark this question as correct. It makes it easier for others having the same problem to find it.
Nifle