我创建了一个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];
谢谢!
答案 0 :(得分: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
答案 1 :(得分:1)
我认为通过“没有发生”你的意思是你看到第一张图片,但序列并没有超越它。
这可能是因为你stopAnimating
太快了:它甚至没有机会开始!
答案 2 :(得分: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];
希望你明白......