Jayson Ong Jayson Ong - 10 months ago 59
iOS Question

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?

Answer Source

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,


     self.navigationController.navigationBar.hidden = YES;


       self.navigationController.navigationBar.hidden = NO;