过渡到 ViewController 离开前一个视图的导航栏
Transitioning to a ViewController leaves the navigation bar of the previous view
我希望通过从 Whosebug 获得的这种转换以编程方式导航到 ViewController。
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];
但是当它转换到视图时,上一个视图的导航栏仍然存在。如何让过渡视图的导航栏出现而不是之前的导航栏?
在您的 AddDeviceViewController
中实施 viewWillAppear
和 viewWillDisappear
。在 viewWillAppear
中隐藏 navigation bar
,在 viewWillDisappear
中显示 navigation bar
。此机制仅隐藏 AddDeviceViewController
的导航栏。像,
-(void)viewWillAppear:(BOOL)animated{
self.navigationController.navigationBar.hidden = YES;
}
-(void)viewWillDisappear:(BOOL)animated{
self.navigationController.navigationBar.hidden = NO;
}
我希望通过从 Whosebug 获得的这种转换以编程方式导航到 ViewController。
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];
但是当它转换到视图时,上一个视图的导航栏仍然存在。如何让过渡视图的导航栏出现而不是之前的导航栏?
在您的 AddDeviceViewController
中实施 viewWillAppear
和 viewWillDisappear
。在 viewWillAppear
中隐藏 navigation bar
,在 viewWillDisappear
中显示 navigation bar
。此机制仅隐藏 AddDeviceViewController
的导航栏。像,
-(void)viewWillAppear:(BOOL)animated{
self.navigationController.navigationBar.hidden = YES;
}
-(void)viewWillDisappear:(BOOL)animated{
self.navigationController.navigationBar.hidden = NO;
}