2016-02-18 33 views
0

我有一個視圖控制器,比如Rootvc。它有一個按鈕,點擊時必須讓另一個視圖控制器,如vc1看起來像一個抽屜。 Rootvc隱藏了其導航欄,但vc1必須顯示其導航欄。起初我使用 CATransition推動vc1。但它將Rootvc變成了黑色。所以,我去了自定義過渡。我的問題是,當我點擊按鈕以推動vc1時,其導航欄立即出現,然後vc1跟隨動畫。彈出vc1的情況也是如此。 vc1的導航欄首先消失,然後vc1的視圖向左滑動。有什麼方法可以使導航欄與其視圖控制器一起生成動畫。我躲在Rootvc的導航欄在viewWillAppear中通過自定義轉換導航欄推動視圖控制器不生成動畫

self.navigationController.navigationBarHidden = YES; 

,並再次在VC1在viewWillAppear中我設置

self.navigationController.navigationBarHidden = NO; 

在敲擊Rootvc

- (IBAction)btnMenuTapped:(UIButton *)sender { 
     [self.navigationController pushViewController:vc1Obj animated:YES]; 
} 

按鈕輕敲後退按鈕上VC1

-(void)backBtnTapped:(UIButton*)sender{ 
     [self.navigationController popViewControllerAnimated:YES]; 
} 

代碼定製轉變

-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext{ 
     UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 
     UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 

     CGRect fromVCFrame = fromVC.view.frame; 
     CGFloat width = toVC.view.frame.size.width; 
//to push vc1  
     if ([fromVC isKindOfClass:[Rootvc class]]) { 
      [[transitionContext containerView] addSubview:toVC.view]; 
      toVC.view.frame = CGRectOffset(fromVCFrame, -width, 0); 

      [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{ 
       fromVC.view.frame = CGRectOffset(fromVCFrame, width, 0); 
       toVC.view.frame = fromVCFrame; 
      } completion:^(BOOL finished) { 
       fromVC.view.frame = fromVCFrame; 
       [transitionContext completeTransition:![transitionContext transitionWasCancelled]]; 
      }]; 
     } 
//to pop vc1 
     if ([fromVC isKindOfClass:[vc1 class]]) { 
     [[transitionContext containerView] addSubview:toVC.view]; 
     [[transitionContext containerView] sendSubviewToBack:toVC.view]; 
     toVC.view.frame = fromVCFrame; 

     [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{ 
      fromVC.view.frame = CGRectOffset(fromVCFrame, -width, 0); 
     } completion:^(BOOL finished) { 
      [transitionContext completeTransition:![transitionContext transitionWasCancelled]]; 
     }]; 
    } 

    } 

也是我要問,如果我不得不使用動畫版的setNavigationBarHidden彈出VC1

回答

0

嘗試設置像removeFromSuperview執行的東西:

[self.navigationController setNavigationBarHidden: YES animated: YES]; 
+0

Thnx 4你的快速反應,但它沒有工作。 – mars

相關問題