导航栏从状态栏下面跳出来怎么办?

4
我在主视图控制器中有一个按钮,使用segue推入一个嵌入的视图控制器导航控制器。
当新视图控制器呈现时,它上面的导航栏会短暂地出现在状态栏下面(状态栏没有隐藏)。与顶部布局指南相关的内容位于正确的位置。动画完成后,它会自行修复。
当再次关闭视图时,同样的事情发生了:主视图控制器短暂地覆盖了状态栏。对于主视图控制器来说,这更为重要,因为它基于UITableViewController;整个表格会跳动。同样,当动画完成时,视图控制器会自行修复。
我尝试关闭导航栏的半透明效果,但问题只会更加明显。在iOS 6上,所有这些都按预期工作。
我在这里上传了一个最简测试案例:https://github.com/tewha/FlipTest
4个回答

3

另一个简单的技巧是这样做:

MasterViewController

当准备Segue时:

 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    [UIView transitionWithView:self.navigationController.view
                      duration:0.75
                       options:UIViewAnimationOptionTransitionFlipFromRight
                    animations:nil
                    completion:nil];
}

当取消加载 AboutViewController

- (IBAction)aboutUnwind:(UIStoryboardSegue *)segue {

[UIView transitionWithView:((UIViewController *)segue.sourceViewController).view
                  duration:0.75
                   options:UIViewAnimationOptionTransitionFlipFromLeft
                animations:nil
                completion:nil];

}


1
这真是个不错的技巧。谢谢。 - Steven Fisher
在“performSegueWithIdentifier:”之后,将调用“prepareForSegue”。您的故事板将触发转换,并且在“prepareForSegue”中意味着进行一些最后一刻的更改。为了使这成为一个更合法的解决方案,而不是一个黑客行为,您应该按照我下面的建议去做。 - user1951992
谢谢 #robdashnash,我会查看你的评论和链接。 - dcorbatta

1
这是iOS7布局系统中的一个错误。我发现将导航控制器视图(而不是推入的视图控制器!)的高度减少状态栏高度,并将其放置在y =状态栏高度会有很大帮助,但状态栏“合并”导航控制器仍会出现轻微闪烁。
另外,看看iOS7.1b1是否仍存在此错误。

1
如果这真的是 iOS 的 bug,我想我只能接受它。这只是个表面问题,一旦 Apple 包含修复程序,我的用户就会得到它。尽管有点烦人。 :) - Steven Fisher
我将接受 doorbatta 的答案,因为他的解决方法更简单。我认为你也可能想看一下。:) 但还是谢谢你。 - Steven Fisher
我知道这个。但对我的情况没有帮助。 - Léo Natan
为什么我的解决方法对你不起作用?你在使用presentModal吗? - dcorbatta

0

iOS 7中导航栏存在问题,导航栏会出现在视图上方或导航栏与视图之间存在间隙。您可以使用以下代码解决此问题:

iOS 7引入了一个新属性,可以像以前的iOS版本一样调整布局行为。将此代码添加到您的视图控制器中,您应该就可以解决问题了。导航栏占用的空间应该会自动计算。

if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
    self.edgesForExtendedLayout = UIRectEdgeNone;

iOS 7 navigation bar jumping / stretching upon viewDidAppear获得的答案。


0

这是英国套件的一个bug。避免使用标准方法

'performSegueWithIdentifier' 或 'presentViewController'

在这里,我从一个控制器转换到另一个控制器,然后在委托回调中返回转换,使用UIView的转换动画。

-(void)photoButtonPressed:(NSNotification*)notification
{        
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Media"
                                                         bundle:nil];

    UINavigationController *navCon = [storyboard instantiateInitialViewController];

    PhotoCaptureViewController *controller = navCon.viewControllers.firstObject;
    controller.delegate = self;

    CustomTabBarViewController *tabBarController = (CustomTabBarViewController*)self.tabBarController;

    [UIView transitionWithView:self.navigationController.view duration:0.75 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
                        [tabBarController.parentViewController addChildViewController:navCon];
                        [tabBarController.parentViewController.view addSubview:navCon.view];
                    } completion:^(BOOL finished) {
                        [navCon didMoveToParentViewController:tabBarController.parentViewController];
                    }];
}

-(void)photoCaptureViewController:(PhotoCaptureViewController *)controller dismissButtonPressed:(UIButton *)dismissButton
{
    CustomTabBarViewController *tabBarController = (CustomTabBarViewController*)self.tabBarController;

    [UIView transitionFromView:controller.navigationController.view toView:tabBarController.view duration:1 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {
        [controller.navigationController willMoveToParentViewController:nil];
        [controller.navigationController removeFromParentViewController];
        [controller.navigationController.view removeFromSuperview];
    }];

}

这是一篇关于容器视图的好文章Khanlou的博客文章


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接