Navigation Bar 向上移动,同时 Navigation Controller 弹出动画

Navigation Bar move up while pop animation of Navigation Controller

在我的根视图中,我创建了一个导航控制器并将其添加到状态栏下方 20 像素处。

我的导航视图控制器

状态栏显示正常

当我单击“返回”时,(屏幕截图冻结动画)。

动画发生时视图向上移动。和 完成后,状态栏又出现了。

代码:这就是我将导航控制器添加到 VC

的方式

在根视图中:

navController = [[UINavigationController alloc]initWithRootViewController:myView];

navController.navigationBar.translucent = YES;
navController.view.autoresizingMask = UIViewAutoresizingNone;

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
    CGRect frame=navController.view.frame;

    frame.origin.y += 20;
    frame.size.height-=20;
    navController.view.frame=frame;
}

所以我相信这是你的问题

frame.origin.y += 20;
frame.size.height-=20;
navController.view.frame=frame;

每次加载视图时都会调用它。我相信如果你多次前进和后退,你的 window 上的视图就会上升。是吗?如是。确保只调用一次。

希望对您有所帮助。

这个回答对我帮助很大

Push / Pop View Controller With Navigation Bar from View Controller Without Navigation Bar

我先添加我的导航控制器 VC,它希望隐藏导航栏

我在下面的代码片段中将其作为 animated:NO。正确的用法必须是使用委托本身的动画 boolean

在VC1: 导航栏应该被隐藏

我必须像下面这样隐藏导航栏。

-(void)viewWillAppear:(BOOL)animated {
    // Hide the bar with animation how viewWillAppear is called
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}

当我将 VC2 推到 VC1 时,我需要重新启用导航栏。因此,在 VC1 本身中,在消失期间我会执行以下操作。

-(void)viewWillDisappear:(BOOL)animated{
    // Show the bar with animation how viewWillDisappear is called
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

在 VC2 中:应显示导航栏

当我在VC2中按回车键时,我实际上又要隐藏导航栏了。所以,我在 viewWillDisappear 中执行此操作。

-(void)viewWillDisappear:(BOOL)animated{
    // Hide the bar with animation how viewWillAppear is called
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}

The Main key is animated:animated and not animated:NO .. Unbelievable.!