1

我创建了一个 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];

谢谢!

4

3 回答 3

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
于 2012-06-28T17:32:15.483 回答
1

我假设“什么都没有发生”是指您看到了第一张图片,但序列并没有超出此范围。

这可能是因为你stopAnimating太早了:它甚至没有机会开始!

于 2012-06-28T17:32:24.770 回答
0

我解决了这个问题,我想问题是因为我没有在我的 imgview 中使用带有框架的 init。这是最终代码:

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

希望你明白...

于 2012-06-28T18:08:38.690 回答