2010-11-17 9 views
0

App iPad. OS 4.2.Spawning infini UIImageViews sans collisions de noms

J'ai un bouton qui, lorsqu'il est pressé, appelle cette fonction qui crée un UIImageView et l'anime (et appelle un second bloc d'animation). J'ai créé un autre bouton qui appelle la même fonction et transmet différents emplacements et différentes URL à un graphique.

Je commence à avoir des problèmes - le premier graphique généré à partir du premier bouton a les emplacements passés à partir du second bouton. Cela est probablement dû au fait que je ne nomme pas dynamiquement UIImageView et n'obtiens pas de collisions à partir de cela.

Alors, comment créer et nommer dynamiquement un nombre infini de UIImageViews? D'autant que, pour référencer UIImageView dans deux fonctions, il faut le déclarer en dehors des fonctions.

-(void)makeSoundEffectWordAppear:(NSString *)imageName:(int)startingX:(int)startingY:(int)endingX:(int)endingY{ 
     myImage = [UIImage imageNamed:imageName]; 
     [testWord setImage:myImage]; 
     testWord = [[[UIImageView alloc] initWithFrame:CGRectMake(startingX,startingY,myImage.size.width,myImage.size.height)] autorelease];  
     [self.view addSubview:testWord]; 
     testWord.alpha=0; 
     testWord.transform = CGAffineTransformMakeScale(.5, .5); 

     [UIView beginAnimations:@"moveWord" context:nil]; 
      [UIView setAnimationDelegate:self]; 
      [UIView setAnimationDidStopSelector:@selector(fadeWord:finished:context:)]; 
      //[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
      [UIView setAnimationDuration:1]; 

      [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
      [UIView setAnimationBeginsFromCurrentState:YES]; 
      testWord.transform = CGAffineTransformMakeScale(1, 1); 
      testWord.center = CGPointMake(endingX,endingY); 
         testWord.alpha=1; 
     [UIView commitAnimations]; 
    } 

- (void)fadeWord:(NSString *)animationID finished:(BOOL)finished context:(void *)context{ 
     [UIView beginAnimations:@"makeWordFade" context:nil]; 
    [UIView setAnimationDelegate:self]; 
     [UIView setAnimationDelay:5]; 
     testWord.alpha=0; 
     testWord.transform = CGAffineTransformMakeScale(.5, .5); 
     [UIView setAnimationDuration:1]; 
    [UIView commitAnimations]; 
} 

Répondre

1

Vous avez un seul pointeur vers testWord plutôt qu'un pointeur pour chaque instance. Vous devriez utiliser la propriété de contexte des animations pour passer dans le UIImageView que vous voulez effacer:

-(void)makeSoundEffectWordAppear:(NSString *)imageName:(int)startingX:(int)startingY:(int)endingX:(int)endingY{ 
    UIImage *myImage = [UIImage imageNamed:imageName]; 
    UIImageView *testWord = [[[UIImageView alloc] initWithImage:myImage] autorelease]; 
    CGRect frame = [testWord frame]; 
    frame.origin.x = startingX; 
    frame.origin.y = startingY; 
    [testWord setFrame:frame]; 
    [self.view addSubview:testWord]; 
    testWord.alpha=0; 
    testWord.transform = CGAffineTransformMakeScale(.5, .5); 

    [UIView beginAnimations:@"moveWord" context:testWord]; 
     [UIView setAnimationDelegate:self]; 
     [UIView setAnimationDidStopSelector:@selector(fadeWord:finished:context:)]; 
     //[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
     [UIView setAnimationDuration:1]; 

     [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
     [UIView setAnimationBeginsFromCurrentState:YES]; 
     testWord.transform = CGAffineTransformMakeScale(1, 1); 
     testWord.center = CGPointMake(endingX,endingY); 
        testWord.alpha=1; 
    [UIView commitAnimations]; 
} 

- (void)fadeWord:(NSString *)animationID finished:(BOOL)finished context:(void *)context{ 
    UIImageView *testWord = (UIImageView *)context; 
    [UIView beginAnimations:@"makeWordFade" context:context]; 
     [UIView setAnimationDelegate:self]; 
     [UIView setAnimationDelay:5]; 
     testWord.alpha=0; 
     testWord.transform = CGAffineTransformMakeScale(.5, .5); 
     [UIView setAnimationDuration:1]; 
    [UIView commitAnimations]; 
}