ios - 状态栏隐藏后 View 被推下?

标签 ios uiviewcontroller uinavigationcontroller ios9 uistatusbar

我有一个没有状态栏的 UIViewController,它会启动第二个有状态栏的 UIViewController

如果扩展状态栏处于事件状态,两个 View 都可以正确显示,但是当我退出第二个 View 并返回到第一个 View 时,我会在顶部看到一个 20pt 的黑条,整个 View 被向下推,遮住底部.

我尝试在 viewDidAppear 中将框架重置为原点 0,0,但没有任何效果。

为什么 View 被下推,我该如何解决?

- (BOOL)prefersStatusBarHidden {
   return YES;
}

- (void)viewDidAppear:(BOOL)animated {
   [super viewDidAppear:animated];
   self.view.frame = CGRectMake(0, 0, self.width, self.height);
   self.view.backgroundColor = [UIColor redColor];
}

- (void)openShare {
  Share *share = [[Share alloc] init];
  UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:share];

  nav.modalTransitionStyle = UIModalPresentationPopover;
  [self presentViewController:nav animated:YES completion:nil];
}

调用 openShare 之前的 View 顶部:

enter image description here

呈现和关闭 Share 后的 View 顶部:

enter image description here

最佳答案

昨天我在我的应用程序中遇到了完全相同的问题。

我做了两件事来解决这个问题。

  1. 我将导航栏上的 Top Space to: Top Layout Guide 约束条件设置为 20(与状态栏高度相同)
    Constaint
  2. 我在有问题的 Controller 中添加了这个 ([self.view layoutSubviews])

    -(void)viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];
    
        [self.view layoutSubviews];
    }
    

关于ios - 状态栏隐藏后 View 被推下?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37197965/

相关文章:

ios - 如何在使用它的 ViewController 上调整自定义(在单独的文件中创建)UIView 高度?

iphone - 使用堆栈的导航 Controller / View Controller

ios - [self.navigationController pushViewController :ngView animated:YES]; not working

objective-c - UINavigationController 的 addChildViewController 和 topViewController 之间的相互作用

ios - Rxswift 更新 Tableview 单元格值

ios - 4 NSarray 进入 pickerview

ios - 如何使用选择器将多个参数传递给 UITapGesture 方法

ios - 项目不会在 xcode 8 中的模拟器上运行

ios - UIViewController 动画停止工作

ios - 选项卡单击应打开 slider 菜单 objective-c