2012-06-28 75 views
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]; 

谢谢!

回答

1

您需要实际添加imgview1以便显示。如果在Interface Builder中创建imgview1,则不需要指定。您也可以在启动后立即停止动画。

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

我创建一个IBOutlet,并连接到我的ImageView,当我使用此代码:[imgview1 setImage:numberSix]。在我的屏幕上初始化numberArray之前它的视图数字6。 – cnaaniomer

+0

我也检查是否我的图像插入到我的数组通过:[imgview1 setImage:[numbersArray objectAtIndex:5]];它的工作。这意味着问题出在我的anumationImages上。 – cnaaniomer

+0

1.确保数组中没有图像为零,如果没有任何图像出现,则没有图像。 2.由于您使用IB连接,因此请勿分配它!或者您将过度编写IB连接。 – Joe

1

我假设通过“什么也没有发生”,你的意思是你看到第一个图像,但是序列不会超出这个范围。

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

0

我解决了这个问题,我猜这个问题是因为我没有使用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]; 

希望你明白...