gpt4 book ai didi

iphone - animationArray 只播放最后一张图片

转载 作者:行者123 更新时间:2023-11-28 23:15:52 25 4
gpt4 key购买 nike

我目前有一个调用 playAnimationToNumber 的方法 buttonHit,它接受一个 int,然后依次用于运行一个循环,为每次迭代播放图像数组,但它似乎只播放最后一个数组..可以你知道为什么吗?因为我有点迷路了,希望能得到帮助。

//attached to button and it calls animation method.
- (void)buttonHit:(id)sender{
[self playAnimationToNumber:5];
}



- (void)playAnimationToNumber:(int)number{

for (int counter=1; counter<=number; counter++) {

NSString *imageNameForFirstNumber = [NSString stringWithFormat:@"Flap%i.png", counter];
NSArray *imagesForAnimation = [NSArray arrayWithObjects:[UIImage imageNamed:@"FlapMoving1.png"], [UIImage imageNamed:@"FlapMoving2.png"], [UIImage imageNamed:imageNameForFirstNumber], nil];


animationArray.animationImages = [[NSArray alloc] initWithArray:imagesForAnimation];

animationArray.animationDuration = 0.5;
animationArray.animationRepeatCount = 1;
[animationArray startAnimating];
[self.view addSubview:animationArray];



}


[animationArray release];
}

工作代码'- (void)playAnimationToNumber:(int)number{

NSMutableArray *imagesForAnimation = [[NSMutableArray alloc] initWithCapacity:0];


for (int counter=1; counter<=number; counter++) {

NSString *imageNameForFirstNumber = [NSString stringWithFormat:@"Flap%i.png", counter];
[imagesForAnimation addObject:[UIImage imageNamed:@"FlapMoving1.png"]];
[imagesForAnimation addObject:[UIImage imageNamed:@"FlapMoving2.png"]];
[imagesForAnimation addObject:[UIImage imageNamed:imageNameForFirstNumber]];
}
animationArray.animationImages = [NSArray arrayWithArray:imagesForAnimation];

animationArray.animationDuration = 5.9;
animationArray.animationRepeatCount = 1;
[animationArray startAnimating];
[self.view addSubview:animationArray];
[imagesForAnimation release];

}'

最佳答案

给你试试这个代码。

   - (void)playAnimationToNumber:(int)number{

NSMutableArray *imagesForAnimation = [[[NSMutable alloc] initWithCapacity:0] autoRelease];
[imagesForAnimation addObject:[UIImage imageNamed:@"FlapMoving1.png"]];
[imagesForAnimation addObject:[UIImage imageNamed:@"FlapMoving2.png"]];

for (int counter=1; counter<=number; counter++) {

NSString *imageNameForFirstNumber = [NSString stringWithFormat:@"Flap%i.png", counter];
[imagesForAnimation addObject:[UIImage imageNamed:imageNameForFirstNumber]];
}
animationArray.animationImages = [NSArray arrayWithArray:imagesForAnimation];

animationArray.animationDuration = 0.5;
animationArray.animationRepeatCount = 1;
[animationArray startAnimating];
[self.view addSubview:animationArray];



}
}

关于iphone - animationArray 只播放最后一张图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6393304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com