animationArray воспроизводит только последнее изображение - PullRequest
0 голосов
/ 18 июня 2011

В настоящее время у меня есть этот метод buttonHit, который вызывает playAnimationToNumber, который принимает 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];   

1 Ответ

2 голосов
/ 18 июня 2011

Вот, пожалуйста, попробуйте этот код.

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



        }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...