2009-04-10 6 views
1

J'essaie une application à plusieurs vues, mais je n'arrive pas à faire disparaître le premier contrôleur de vue lorsque j'apporte le nouveau contrôleur de vue. Je pose le second contrôleur de vue (à venir) à l'index 0, et je le place juste en arrière-plan. Je pensais que le [going.view removeFromSuperview] supprimerait le viewcontroller original, mais ce n'est pas ce qui se passe ...Faire disparaître un contrôleur de vue

UIViewController *coming = nil; 
    UIViewController *going = nil; 
    UIViewAnimationTransition transition; 

    if (answer == YES) 
    { 
     coming = boyController; 
     going = getInfoController; 
     transition = UIViewAnimationTransitionFlipFromLeft; 
    } 
    else 
    { 
     coming = girlController; 
     going = getInfoController; 
     transition = UIViewAnimationTransitionFlipFromLeft; 
    } 
    NSLog(child); 
    [UIView setAnimationTransition:transition forView: self.view cache:YES]; 
    [coming viewWillAppear:YES]; 
    [going viewWillDisappear:YES]; 
    [going.view removeFromSuperview]; 
    [self.view insertSubview:coming.view atIndex:0]; 
    [going viewDidDisappear:YES]; 
    [coming viewDidAppear:YES]; 

    [UIView commitAnimations]; 

Répondre

1

D'abord un peu refactoring:

coming = (answer ? boyController : girlController); 

Vous pouvez supprimer going et transition, car ils ne sont utilisés qu'une seule fois. Ensuite, pour réellement faire l'animation, vous devez tout mettre dans le contexte d'un bloc d'animation.

[UIView beginAnimations:@"flipAnimation" context:NULL]; 
[UIView setAnimationTransition:transition forView:self.view cache:YES]; 
[getInfoController.view removeFromSuperview]; 
[self.view addSubview:coming.view]; 
[UIView commitAnimations]; 

viewWillAppear: et viewWillDisappear: sont des méthodes de délégués. Ceux-ci seront appelés automatiquement sur les délégués de ces vues, le cas échéant. Ils ne devraient jamais être appelés manuellement.

Questions connexes