从阵列中的图像(images from an array)

2019-10-16 22:16发布

我创建一个NSMutableArray,我添加了它的图像。 还我创造,我要表现出从阵列图像的ImageView的,我试图用animationImages,但我没有什么事,我该如何解决呢? 这里是我的代码:

    //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];

谢谢!

Answer 1:

您需要实际添加imgview1的东西,以便它显示。 如果imgview1是在Interface Builder创建那么就没有必要分配。 你也启动后立即停止你的动画。

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


Answer 2:

我认为是“什么都没有发生”你的意思是,你看到的第一个图像,但顺序不动不止于此。

这可能是因为你stopAnimating太早:它甚至没有得到一个机会下手!



Answer 3:

我解决问题,我想这个问题是因为我没有用框架使用的init我imgview。 这里是最后的代码:

    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];

希望你明白...



文章来源: images from an array