简体   繁体   中英

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.

  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 . In viewWillAppear hide navigation bar and in viewWillDisappear show navigation bar . This mechanism only hide navigation bar for AddDeviceViewController . Something like,

 -(void)viewWillAppear:(BOOL)animated{

     self.navigationController.navigationBar.hidden = YES;
 }

 -(void)viewWillDisappear:(BOOL)animated{

       self.navigationController.navigationBar.hidden = NO;
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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