iOS来电状态栏更新,视图控制器以模态方式呈现在屏幕上。

8

由于经过了长达2天的谷歌搜索、Stack Overflow等大量研究,我才敢提出这个问题...

我的问题是:我想要从我的主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)。问题在于,当用户在我的应用程序中完成通话时,状态栏会调整为普通大小,但模态VC不会向上移动。
我是通过此通知在代码中了解到这一情况的:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statuBarChange:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];

最糟糕的情况是框架正确,但是原点仍然是(0,0)

有没有一种方法可以刷新模态呈现的视图控制器?而不需要解除显示并再次呈现它?


为什么你要投反对票?我写这个问题是为了找到答案。关于模态VC和inCall状态栏的行为,没有类似的东西。 如果你投反对票,请解释一下原因,这样我才能理解。 - Shial
2个回答

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

UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;

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

0

你真的需要为这个模态窗口创建自定义转场吗?如果不需要,请删除“navigation.modalPresentationStyle = UIModalPresentationCustom”这一行,然后就可以了。

如果你确实需要自定义样式,那么在 iOS 8+ 中使用 UIModalPresentationCustom 样式时会出现已知的状态栏 bug。据我所知,你需要通过 animateTransition 和将框架推到正确位置来解决这个问题。

还有一个可怕的 hack 方法是在下面的应用程序委托中使用 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。

我不喜欢所有这些解决方案,但它应该为您提供可行的解决方案,具体取决于您的项目设置以及是否可以忽略临时模态对话框中的那个小空间。


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