1

i create an nsmutableArray and i add for it an images. also i create an imageView that i want to show the images from the array, i tried to use animationImages but i nothing is happened, how can i fix it? here is my code:

    //Numbers images
    UIImage *numberZero = [UIImage imageNamed:@"numberZero.png"];
    UIImage *numberOne = [UIImage imageNamed:@"numberOne.png"];
    UIImage *numberTwo = [UIImage imageNamed:@"numberTwo.png"];
    UIImage *numberThree = [UIImage imageNamed:@"numberThree.png"];
    UIImage *numberFour = [UIImage imageNamed:@"numberFour.png"];
    UIImage *numberFive = [UIImage imageNamed:@"numberFive.png"];
    UIImage *numberSix = [UIImage imageNamed:@"numberSix.png"];
    UIImage *numberSeven = [UIImage imageNamed:@"numberSeven.png"];
    UIImage *numberEight = [UIImage imageNamed:@"numberEight.png"];
    UIImage *numberNine = [UIImage imageNamed:@"numberNine.png"];

    //add numbers uiimage to numbersArray
    numbersArray = [NSMutableArray arrayWithObjects:numberZero, numberOne, numberTwo, numberThree, numberFour, numberFive, numberSix, numberSeven, numberEight, numberNine, nil];


    imgview1 = [[UIImageView alloc] init];
    imgview1.animationImages = numbersArray;
    imgview1.animationDuration = 2;
    imgview1.animationRepeatCount=0;
    [imgview1 startAnimating];
    [imgview1 stopAnimating];

thanks!

cnaaniomer
  • 97
  • 1
  • 3
  • 10

3 Answers3

1

You need to actually add imgview1 to something so that it displays. If imgview1 was created in Interface Builder then there is no need to assign. Also you stop your animation immediately after starting it.

//If created in IB comment out the next line
imgview1 = [[UIImageView alloc] init];
imgview1.animationImages = numbersArray;
imgview1.animationDuration = 2;
imgview1.animationRepeatCount=0;

//If not created in IB then add this to a view e.g:
[self.view addSubview:imgview1]; 

[imgview1 startAnimating];
//[imgview1 stopAnimating]; this is too soon to stop animating
Joe
  • 56,979
  • 9
  • 128
  • 135
  • i created an iboutlet and connect it to my imageview, when i use this code: [imgview1 setImage:numberSix]; before the initialize of numberArray its view number six on my screen. – cnaaniomer Jun 28 '12 at 17:37
  • i also check if my image was insert to my array via: [imgview1 setImage:[numbersArray objectAtIndex:5]]; ans it work. it means that the problem is with my anumationImages. – cnaaniomer Jun 28 '12 at 17:39
  • 1. Make sure none of the images in the array are nil, if one is nil none of the images after it will show up. 2. Since you connected using IB do not assign it!! or you will over write the IB connection. – Joe Jun 28 '12 at 17:42
  • i checked all my images in the array and none of then in nil. and what are mean when u say that i use too soon stopAnimation? – cnaaniomer Jun 28 '12 at 17:59
  • +1 it looks like we both caught two separate pieces of the problem :) – Sergey Kalinichenko Jun 28 '12 at 18:21
  • @cnaaniomer If you call startAnimation and then immediately stopAnimation the user will not see any animation. You will need to set up a timer or something or use some kind of user interaction to stop the animation. – Joe Jun 28 '12 at 18:26
1

I assume that by "nothing happened" you mean that you see the first image, but the sequence does not move beyond that.

This is probably because you stopAnimating too soon: it does not even get a chance to start!

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
0

i solve the problem, i guess the problem were because i didn't use init with frame to my imgview. here is the final code:

    UIImageView *imgview1 = [[UIImageView alloc] initWithFrame:CGRectMake(40, 90, 240, 240)];
    imgview1.animationImages = numbersArray;
    imgview1.animationDuration = 2;
    imgview1.animationRepeatCount=1;
    [imgview1 startAnimating];
    [self.view addSubview:imgview1];

hope u understand...

cnaaniomer
  • 97
  • 1
  • 3
  • 10