Auto Layout and in-call status bar

喜欢而已 提交于 2019-11-29 01:29:59
herzi

(Using answer instead of comment due to lack of reputation, sorry.)

I ran into this issue as well and was trying out e.g. the solution pointed out above: It didn't work for me.

So I created a repository with example code to expose the original poster's problem. There are example applications for these scenarios:

  1. the Custom View Controller is the window's root view controller,
  2. the Custom View Controller is a child of a UINavigationController which is the window's root view controller,
  3. the Custom View Controller is a child of a UITabBarController which is the window's root view controller and
  4. the Custom View Controller is a child of a UINavigationController which is as child of a UITabBarController which is the window's root view controller.

It turned out that the solution from CEarwood actually works… when the custom view controller is a child of a UINavigationController (cases 2 and 4). Hoewever, it does not work in cases 1 and 3.

I hope this information is useful.

CEarwood

For a purely Auto Layout answer you can get a reference to the bottom constraint and adjust its constant when UIApplicationWillChangeStatusBarFrameNotification is received and back to 0 when the DidChange notification is received. Here's the test VC I used:

@interface CEViewController ()

@property (nonatomic, strong) IBOutlet NSLayoutConstraint *bottomConstraint;

@end

@implementation CEViewController

- (void)viewDidLoad {
    [super viewDidLoad];        

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

- (void)statusBarFrameWillChange:(NSNotification *)note {
    NSValue *newFrameValue = [note userInfo][UIApplicationStatusBarFrameUserInfoKey];

    self.bottomConstraint.constant = newFrameValue.CGRectValue.size.height;
    [self.view setNeedsLayout];
}

- (void)statusBarFrameDidChange:(NSNotification *)note {
    self.bottomConstraint.constant = 0;
    [self.view setNeedsLayout];
}

@end
Marcel

This is an effect from the screen resizing.

When the in-call status bar appears, the view resizes to the size it should have with the in-call status bar active and then moves down as the status bar changes size.

For a brief moment, the view under the table view is visible. What you could do is add a view under the table view extending downwards out of the screen to cover-up the background color.

Another approach is with your AppDelegate, implement:

-application:willChangeStatusBarFrame:

and resize the table view to cover the bit that gets exposed. Then when -application:didChangeStatusBarFrame: gets called, resize it back to the original size.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!