Array Images

I create nsmutableArray and add images for it. I also create an imageView that I want to show images from an array, I tried to use animationImages, but nothing 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!

+1
objective-c nsmutablearray animation uiimageview
source share
3 answers

You need to add imgview1 to something so that it displays. If imgview1 was created in Interface Builder, then there is no need to assign. You also stop the animation immediately after it starts.

 //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 eg: [self.view addSubview:imgview1]; [imgview1 startAnimating]; //[imgview1 stopAnimating]; this is too soon to stop animating 
+1
source share

I assume that โ€œnothing happenedโ€ means that you see the first image, but the sequence does not go beyond that.

This is probably because you stopAnimating too soon: it doesnโ€™t even have the opportunity to start!

+1
source share

I am solving a problem, I think the problem is that I did not use init with a frame for 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]; 

I hope you understand ...

0
source share

All Articles