iOS in-call状态栏更新viewcontroller在屏幕上呈现modaly

我有能力提出这个问题,因为经过大量的研究,几乎2天的谷歌搜索,Stack Overflowing等…

我的问题是:我从我的主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)

有没有办法反映模态提出的vc?没有解雇并再次提出它?

解决方法

你真的需要这种模式的自定义过渡吗?如果没有,删除行“navigation.modalPresentationStyle = UIModalPresentationCustom”,你就可以了.

如果确实需要自定义样式,这是iOS 8中状态栏中UIModalPresentationCustom样式的已知错误. AFAIK,你必须使用animateTransition来破解它并将框架推到适当的位置.

在下面的app委托中使用willChangeStatusBarFrame还有一个非常糟糕的黑客攻击.您可以通过检测是否实际存在模态以及动画更改来改进它.

- (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.

我讨厌所有这些解决方案,但它应该根据项目的设置方式给你一些可行的东西,如果你不能忽略那个临时模态对话框的小空间.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...