【问题标题】:iOS in-call status bar update viewcontroller presented modaly on screeniOS 通话状态栏更新视图控制器以模态方式呈现在屏幕上
【发布时间】:2015-03-05 07:10:21
【问题描述】:

我有能力问这个问题,因为经过近 2 天的 Google 搜索、堆栈溢出等大型研究......

我的问题是这样的:我正在从我的主 ViewController 中呈现 ViewController,如下所示:

UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:VController];
navigation.transitioningDelegate = self;
navigation.modalPresentationStyle = UIModalPresentationCustom;

[self presentViewController:navigation
                   animated:YES
                 completion:nil];

每当 iPhone 用户通话或将他或她的手机用作热点时,状态栏都会放大,将我的模式呈现的 VC 推到底部,但原点设置为 (0;0) 问题是当用户在我的应用程序状态栏中完成呼叫时,将其调整为正常大小,但 Modal VC 没有向上移动。

多亏了这个通知,我在代码中发生这种情况时就知道了:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statuBarChange:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];

最糟糕的是帧是正确的并且原点仍然是(0,0)

有没有办法 refres modal 呈现的 vc ?没有解雇并再次呈现?

【问题讨论】:

  • 你为什么投反对票?我写了这个问题来寻找和回答。模态 VC 和 inCall 状态栏呈现的行为没有任何相似之处。如果您投反对票,请解释原因,然后我可以与之相关。

标签: ios autolayout statusbar presentmodalviewcontroller in-call


【解决方案1】:

您真的需要此模式的自定义过渡吗?如果没有,请删除“navigation.modalPresentationStyle = UIModalPresentationCustom”行,您就可以开始了。

如果您确实需要自定义样式,这是 iOS 8+ 中 UIModalPresentationCustom 样式和状态栏的已知错误。 AFAIK,您必须使用 animateTransition 解决这个问题,并将帧推到适当的位置。

在下面的应用程序委托中使用 willChangeStatusBarFrame 也有一个可怕的 hack。您可以通过检测是否真的有一个模态来改进它,并对变化进行动画处理。

- (void)application:(UIApplication *)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame
{
    if (newStatusBarFrame.size.height < 40) {
        for (UIView *view in self.window.subviews) {
            view.frame = self.window.bounds;
        }
    }
}

另一种选择是让模态框覆盖状态栏,并覆盖该视图控制器的 prefersStatusBarHidden。

我讨厌所有这些解决方案,但它应该为您提供一些可行的东西,具体取决于您的项目设置方式,以及如果您不能忽略用于临时模态对话框的小空间。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-08
    • 2013-09-09
    • 2016-06-08
    • 2011-01-20
    • 2016-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多