images from an array

假如想象 提交于 2019-12-24 09:26:19

问题


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!


回答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



回答2:


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!




回答3:


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...



来源:https://stackoverflow.com/questions/11249876/images-from-an-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!