简体   繁体   中英

iOS in-call status bar update viewcontroller presented modaly on screen

I'm afford to ask this question because after large research almost 2days of Googling, Stack Overflowing, etc...

My issue is this: I'm presenting ViewController from my main ViewController like this:

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

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

whenever an iPhone user is in call, or is using his or her phone as a hotspot, status bar is enlarged pushing my modaly presented VC to the bottom but the origin is set to (0;0) The problem is when user finish call during he is in my application status bar resize to normal size but Modal VC didnt move up.

在此处输入图像描述

I knew about this when it happen in code thanks to this notification:

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

The worst thing is that the frames are corect and origin are still (0,0)

is there a way to refres modal presented vc? with out dissmiss and presenting it again?

Do you really need a custom transition for this modal? If not, remove the line "navigation.modalPresentationStyle = UIModalPresentationCustom" and you're good to go.

If you do need a custom style, this is a known bug with the UIModalPresentationCustom style in iOS 8+ and the status bar. AFAIK, you'll have to hack around this with animateTransition and shoving the frames around into the proper places.

There's also an awful hack for this using willChangeStatusBarFrame in the app delegate below. You can improve it with detecting if there's actually a modal up, and animating the change.

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

Another alternative is to make the modal cover the status bar, and override prefersStatusBarHidden for that view controller.

I hate all these solutions, but it should give you something workable depending how your project is set up, and if you can't ignore that little space for a temporary modal dialog.

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM