简体   繁体   English

过渡到ViewController会离开上一个视图的导航栏

[英]Transitioning to a ViewController leaves the navigation bar of the previous view

I want the programmatically navigate to a ViewController with this kind of transitioning that I got from stackoverflow. 我想以编程方式导航到ViewController,并从stackoverflow获得这种过渡。

  CATransition* transition = [CATransition animation];
  transition.duration = .45;
  transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  transition.type = kCATransitionFade;
  self.navigationController.view.layer addAnimation:transition forKey:kCATransition];

  UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
  AddDeviceViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"AddDeviceViewController"];
  self.navigationController pushViewController:vc animated:NO];

But when it transitions to the View, the navigation bar from the previous view stays. 但是,当它过渡到视图时,前一个视图的导航栏会保留。 How can I make the Navigation Bar of the transitioned View appear instead of the previous one? 如何显示过渡视图的导航栏而不是上一个视图?

Implement viewWillAppear and viewWillDisappear in your AddDeviceViewController . 在您的AddDeviceViewController实现viewWillAppearviewWillDisappear In viewWillAppear hide navigation bar and in viewWillDisappear show navigation bar . viewWillAppear隐藏navigation bar ,在viewWillDisappear显示navigation bar This mechanism only hide navigation bar for AddDeviceViewController . 此机制仅隐藏AddDeviceViewController导航栏。 Something like, 就像是,

 -(void)viewWillAppear:(BOOL)animated{

     self.navigationController.navigationBar.hidden = YES;
 }

 -(void)viewWillDisappear:(BOOL)animated{

       self.navigationController.navigationBar.hidden = NO;
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM