Don't like ads? PRO users don't see any ads ;-)
Guest

ViewManager animation

By: a guest on May 9th, 2012  |  syntax: None  |  size: 2.52 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. - (void)slideInController:(UINavigationController *)newNavController
  2. {  
  3.     UINavigationController *oldNavController = (UINavigationController *)[AppDelegate rootVC];
  4.    
  5.     NSMutableArray *newControllers = [NSMutableArray arrayWithArray:newNavController.viewControllers];
  6.  
  7.     NSLog(@"Newcontrollers: %@", newControllers);
  8.    
  9.     UIViewController *newTopController = [newControllers lastObject];
  10.     UIViewController *oldTopController = oldNavController.visibleViewController;
  11.    
  12.     [newControllers removeObject:[newControllers lastObject]];
  13.     [newControllers addObject:oldTopController];
  14.    
  15.     NSMutableArray *oldControllers = [NSMutableArray arrayWithArray:oldNavController.viewControllers];
  16.     [oldControllers removeObject:[oldControllers lastObject]];
  17.    
  18.     newNavController.viewControllers = newControllers;
  19.    
  20.     [AppDelegate setRootVC:newNavController];
  21.    
  22.  
  23.  
  24.     oldNavController.viewControllers = oldControllers;
  25.  
  26.     [newNavController.visibleViewController.view insertSubview:newTopController.view belowSubview:self.bottomMenu.view];
  27.    
  28.     newTopController.view.layer.transform = CATransform3DMakeTranslation(0, 600, 0);
  29.    
  30.     float slideOffset = 0;
  31.    
  32.     if (!newTopController.wantsFullScreenLayout && oldTopController.wantsFullScreenLayout)
  33.         slideOffset = [[UIApplication sharedApplication] statusBarFrame].size.height;
  34.    
  35.     if (newTopController.wantsFullScreenLayout && !oldTopController.wantsFullScreenLayout)
  36.         slideOffset = - [[UIApplication sharedApplication] statusBarFrame].size.height;
  37.    
  38.     [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationCurveEaseOut animations:^{
  39.         newTopController.view.layer.transform = CATransform3DMakeTranslation(0, 0 + slideOffset, 0);
  40.     } completion:^(BOOL finished) {
  41.        
  42.         [newTopController.view removeFromSuperview];
  43.        
  44.          newTopController.view.layer.transform = CATransform3DMakeTranslation(0, 0, 0);
  45.        
  46.         [oldNavController setViewControllers:[oldNavController.viewControllers arrayByAddingObject:oldTopController]];;
  47.         [newControllers removeLastObject];
  48.        
  49.         self.bottomMenu.view.frame = CGRectMake(0, HEIGHTOF(newTopController.view) - HEIGHTOF(self.bottomMenu.view), WIDTHOF(self.bottomMenu.view), HEIGHTOF(self.bottomMenu.view));
  50.        
  51.         [newTopController.view addSubview:self.bottomMenu.view];
  52.        
  53.         newNavController.viewControllers = [newControllers arrayByAddingObject:newTopController];
  54.                
  55.     }];
  56.  
  57. }