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:25

The solution is to ensure you have made your window key:

[window makeKeyAndVisible];

If you don't do that the subview does not get resized automatically, but there are no other symptoms as far as I know.

查看更多
劫难
3楼-- · 2019-01-06 13:29

You will have to update the views manually if you are setting your view frames programatically

 -(void) viewDidAppear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(statusBarFrameWillChange:)name:UIApplicationWillChangeStatusBarFrameNotification object:nil];

}

- (void)statusBarFrameWillChange:(NSNotification*)notification
{
// respond to changes
NSLog(@"STATUS BAR UPDATED");
NSDictionary *statusBarDetail = [notification userInfo];
NSValue *animationCurve = statusBarDetail[UIApplicationStatusBarFrameUserInfoKey];
CGRect statusBarFrameBeginRect = [animationCurve CGRectValue];
int statusBarHeight = (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication]statusBarOrientation])) ? statusBarFrameBeginRect.size.height : statusBarFrameBeginRect.size.width;

NSLog(@"status bar height  %d", statusBarHeight);
}

-(void) viewDidDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationBackgroundRefreshStatusDidChangeNotification object:nil];
}

This gives you the new height of the status bar and using this you can update your frames accordingly.

查看更多
混吃等死
4楼-- · 2019-01-06 13:32

I was having the same problem. What I did was this.

  1. Open the xib file in IB
  2. All interface elements are by default attached to move along with with top and shown in the 'Autosizing' property in the 'Size Inspector'. So, for the UI elements at the bottom of the screen, remove the link from top and instead make the link from bottom. Leave all the others as is.
  3. Problem Solved!!!

I hope I was clear.

查看更多
叼着烟拽天下
5楼-- · 2019-01-06 13:33

iOS will invoke your viewController's viewWillLayoutSubviews method whenever there is a change in status bar. You can override that and adjust your subviews according to the new bounds.

- (void)viewWillLayoutSubviews {
    // Your adjustments accd to 
    // viewController.bounds

    [super viewWillLayoutSubviews];
}
查看更多
forever°为你锁心
6楼-- · 2019-01-06 13:34

You're looking for -[UIApplication statusBarFrame] and, in your UIApplicationDelegate, you should implement this delegate method to be notified of when the status bar's frame changes:

- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame  
查看更多
我只想做你的唯一
7楼-- · 2019-01-06 13:40

For views like UITableView you'll typically need to change the table cell height, and there's no other way to do it except to implement application:didChangeStatusBarFrame:. But it's no biggie, and you can set the row height to non-integer values if you need to.

查看更多
登录 后发表回答