Resize for in-call status bar?

2019-01-06 12:42发布

How can I make my view resize in response to the in-call status bar from my nib?

I figured it would just be setting the resize properties, but they're not enabled for the root UIView.

(I think my main problem here is I don't know what any of this is called; I can't find any reference to the in-call status bar in any of the documentation except where it talks about the simulator menu command.)

11条回答
看我几分像从前
2楼-- · 2019-01-06 13:42

The notification for status bar changing frame is

UIApplicationWillChangeStatusBarFrameNotification

Register as an observer:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameWillChange:)name:UIApplicationWillChangeStatusBarFrameNotification object:nil];

Then respond to change in your handler:

- (void)statusBarFrameWillChange:(NSNotification*)notification { // respond to changes }

Even with autolayout setup correctly, you may need to respond to changes. For example, a table view that calculates its cell height based on the given space in the screen would may need to reloadData after the status bar changed.

Documentation

查看更多
看我几分像从前
3楼-- · 2019-01-06 13:43

None of the solutions posted before worked for me. What did work for me was that I didn't have my constraints set up properly for my views. In my situation, I had two different container views within my view.

View of scene in storyboard.

The bottom (in the list) container view was a UITableView, which was not scrolling correctly to the bottom of the table. The reason was that the offset of the in-call status bar was causing the origin (top-left corner) of the UITableView to change, but the size would remain this same. This meant that the bottom of the table was off screen!

The solution was to correctly set the Autoresizing height constraint properly. In the screenshot below, it is the vertical arrows in the middle of the Autoresizing box.

enter image description here

查看更多
Deceive 欺骗
4楼-- · 2019-01-06 13:44

What do you mean when you say that 'the resize properties aren't enabled for the root UIView'?

The in-call status bar doesn't have any particular special designation, and I don't think there are any APIs or notifications around it. Instead, your views should simply be set up to autoresize correctly.

Try creating a new navigation-based app in Xcode and study the autoresize settings on the table view in RootViewController.xib. Hopefully you'll see a delta between what Apple's set and what you've set in your project.

查看更多
你好瞎i
5楼-- · 2019-01-06 13:44

A view may not resize automatically with status bar size changes if you do not have a root view controller set. I originally had this in my app delegate, and my app worked properly in all regards except that it would not resize correctly during phone calls.

[self.window addSubview:rootController.view];

I changed the above line to this, and now my app resizes automatically during calls.

[self.window setRootViewController:rootController];

I discovered this fix after seeing this in the log and investigating the cause.

Application windows are expected to have a root view controller at the end of application launch
查看更多
你好瞎i
6楼-- · 2019-01-06 13:48

this works for me perfectly when my application is running in background and I press command + T. In my scenario , the root controller is my tab bar controller and I am readjusting my nav controller inside each tab.

- (void)application:(UIApplication *)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame{
[UIView animateWithDuration:0.35 animations:^{
    CGRect windowFrame = ((UINavigationController *)((UITabBarController *)self.window.rootViewController).viewControllers[0]).view.frame;
    if (newStatusBarFrame.size.height > 20) {
        windowFrame.origin.y = newStatusBarFrame.size.height - 20 ;// old status bar frame is 20
    }
    else{
        windowFrame.origin.y = 0.0;
    }
    ((UINavigationController *)((UITabBarController *)self.window.rootViewController).viewControllers[0]).view.frame = windowFrame;
}];

}

查看更多
登录 后发表回答