1.首先设置代理 <UINavigationControllerDelegate>
navigationcontroller.delegate = self;
2.实现代理协议方法
#pragma mark - UINavigationController delegate
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
//子控制器的个数
int count = navigationController.viewControllers.count;
if (count == 2) {
//隐藏工具栏
[self hiddenTabbar:YES];
float height = kScreenHeight-20;
if (ios7) {
height = kScreenHeight;
}
navigationController.view.height = height;
}
else if(count == 1) {
//显示工具栏
[self hiddenTabbar:NO];
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
//子控制器的个数
int count = navigationController.viewControllers.count;
if (count == 2) {
//隐藏工具栏
[self hiddenTabbar:YES];
float height = kScreenHeight-20;
if (ios7) {
height = kScreenHeight;
}
navigationController.view.height = height;
}
else if(count == 1) {
//显示工具栏
[self hiddenTabbar:NO];
//动画效果
[self performSelector:@selector(navimovefunction:) withObject:navigationController afterDelay:.35];
}
}
[self performSelector:@selector(navimovefunction:) withObject:navigationController afterDelay:.35];
}
}
3.//是否隐藏工具栏,在代理方法中调用
- (void)hiddenTabbar:(BOOL)hidden
{
float time = 0.35;
if (ios7) {
time = 0.25;
}
[UIView animateWithDuration:time animations:^{
if (hidden) {
_tabbarView.left = -kScreenWidth;
} else {
_tabbarView.left = 0;
}
}];
}
- (void)hiddenTabbar:(BOOL)hidden
{
float time = 0.35;
if (ios7) {
time = 0.25;
}
[UIView animateWithDuration:time animations:^{
if (hidden) {
_tabbarView.left = -kScreenWidth;
} else {
_tabbarView.left = 0;
}
}];
}