我有39个项目(动画,动画声音,图像声音),每个动画帧有50个图像(即39x50)。如果你考虑刷牙'意思是我有刷牙声,刷动画(50),他们的动画声音。所有39个项目都有这三个部分。这些动画我将使用for循环顺序调用。
//methodB
- (void) methodB {
[self animationSound];
if (counter == 0){
NSMutableArray *dashBoy = [NSMutableArray array];
for (i = 1; i <= 20; i++) {
butterfly = [NSString stringWithFormat:@"brush_%d.png", i];
if ((image = [UIImage imageNamed:butterfly]))
[dashBoy addObject:image];
}
[stgImageView setAnimationImages:dashBoy];
[stgImageView setAnimationDuration:3.9f];
[stgImageView startAnimating];
}
.
.
.
if(counter == 38) {
NSMutableArray *dashBoy38 = [NSMutableArray array];
for (i = 1; i <= 6; i++) {
butterfly = [NSString stringWithFormat:@"wash_%d.png", i];
if ((image = [UIImage imageNamed:butterfly]))
[dashBoy38 addObject:image];
}
[stgImageView setAnimationImages:dashBoy38];
[stgImageView setAnimationDuration:2.0f];
[stgImageView startAnimating];
}
}
然后我有两个按钮,下一个和上一个,我的动作是,如果我点击下一个按钮,图像将改变,2秒延迟播放相应的动画与动画声音,然后单击上一个按钮反之亦然。
//next and previous function
-(void)btnClicked:(UIButton*)btn{
[stgImageView stopAnimating];
[myTimer invalidate];
if (btn.tag==1) {
counter++;
if (counter == [stgImageArray count])
counter = 0;
[stgImageView setImage:[UIImage imageNamed:[stgImageArray objectAtIndex:counter]]];
stgText.text= [NSString stringWithFormat:@"%@", [stgTextArray objectAtIndex:counter]];
myTimer = [NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:@selector(methodB) userInfo:nil repeats:NO];
}
else{
counter--;
if (counter < 0)
counter = 39;
[stgImageView setImage:[UIImage imageNamed:[stgImageArray objectAtIndex:counter]]];
stgText.text= [NSString stringWithFormat:@"%@", [stgTextArray objectAtIndex:counter]];
myTimer = [NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:@selector(methodB) userInfo:nil repeats:NO];
}
}
问题是如果连续点击下一个或上一个按钮,应用程序将在我的iPad中崩溃。如果有人告诉我如何使用他们的动画和动画声音管理这39个项目。
我想如果我点击下一个按钮图像将会改变,并且在2秒动画播放和动画声音之后再点击另一次上一个动画将停止并用动画改变图像等等。