TransitionFromView: toView: duration: options: complete: does not animate transition

I have a view controller that displays the views of 2 submatrix controllers in a given area of ​​its view. 2nd view controllers are FlopVC and FipVC.

I want to animate the transition from one subtitle to another. The code I'm using is:

-(IBAction)flip:(id)sender{ UIViewController *newVC = nil; if (self.isFlip) { newVC = [[FlopVC alloc] initWithNibName:nil bundle:nil]; }else{ newVC = [[FipVC alloc] initWithNibName:nil bundle:nil]; } newVC.view.frame = CGRectMake(120, 20, 240, 260); [self.view addSubview:newVC.view]; [UIView transitionFromView:self.currentVC.view toView:newVC.view duration:0.9 options:UIViewAnimationTransitionFlipFromLeft completion:^(BOOL finished) { self.currentVC = newVC; self.isFlip = ! self.isFlip; }]; } 

Submenus are replaced, but without animation. What am I doing wrong?

PS the full project is here .

+7
source share
3 answers
  UIView Animation TransitionFlipFromLeft! = UIView Animation TransitionFlipFromLeft 
+19
source

if you are using the new iOS5 presentation container paradigm, you need to do something in the following lines:

 -(IBAction)flip:(id)sender{ UIViewController *newVC = nil; if (self.isFlip) { newVC = [[FlopVC alloc] initWithNibName:nil bundle:nil]; }else{ newVC = [[FipVC alloc] initWithNibName:nil bundle:nil]; } newVC.view.frame = CGRectMake(120, 20, 240, 260); // required for the new viewController container self.currentVC willMoveToParentViewController:nil]; [self addChildViewController:newVC]; [self transitionFromViewController:self.currentVC toViewViewController:newVC.view duration:0.9 options: UIViewAnimationOptionTransitionFlipFromLeft animations:nil completion:^(BOOL finished) { // required for the new viewController container [self.currentVC removeFromParentViewController]; [newVC didMoveToParentViewController:self]; self.currentVC=newVC; }]; } 

refer to the Deploying the 2011 WWDC Container and Video View Controller on UIViewController containers section for more information.

+3
source

Here is the working code that (by pure coincidence) does exactly what you describe. My two child vc are stored in self->swappers . The integer cur keeps track of which one is currently displayed. The point in my interface where the subtitle will be displayed is indicated by the view output, panel .

 UIViewController* fromvc = [self->swappers objectAtIndex:cur]; cur = (cur == 0) ? 1 : 0; UIViewController* tovc = [self->swappers objectAtIndex:cur]; tovc.view.frame = self.panel.bounds; // must have both as children before we can transition between them [self addChildViewController:tovc]; // "will" called for us // note: when we call remove, we must call "will" (with nil) beforehand [fromvc willMoveToParentViewController:nil]; [self transitionFromViewController:fromvc toViewController:tovc duration:0.4 options:UIViewAnimationOptionTransitionFlipFromLeft animations:nil completion:^(BOOL done){ // note: when we call add, we must call "did" afterwards [tovc didMoveToParentViewController:self]; [fromvc removeFromParentViewController]; // "did" called for us }]; 
+2
source

All Articles