0

I am making a sliding menu. But when I slide-open and slide close, the front view controller's navigation bar overlaps with system status bar.

enter image description here

if (should_hide_status_bar)
{
    [[UIApplication sharedApplication] setStatusBarHidden:is_going_to_open withAnimation:(UIStatusBarAnimationSlide)];
}

[UIView animateWithDuration:DURATION delay:0 usingSpringWithDamping:2 initialSpringVelocity:1 options:(0) animations:^
{
    CGFloat             disp0   =   state == AASlideViewControllerSlidingStateClose ? 0 : OPEN_X_POS;
    CGAffineTransform   t1      =   CGAffineTransformMakeTranslation(disp0, 0);

    self.frontViewController.view.transform =   t1;
}
completion:^(BOOL finished)
{
    self->_flags.is_sliding             =   NO;
    self.view.userInteractionEnabled    =   YES;
}];

How to fix this?

eonil
  • 83,476
  • 81
  • 317
  • 516

1 Answers1

0

This is simply because you are setting the status bar visibility out of the animation block. Move it into the animation block and we'll see it's working correctly.

BOOL const      should_hide_status_bar  =   _shouldHideStatusBarWhenOpen;
BOOL const      is_going_to_open        =   state == AASlideViewControllerSlidingStateOpen;

[UIView animateWithDuration:DURATION delay:0 usingSpringWithDamping:2 initialSpringVelocity:1 options:(0) animations:^
{
    CGFloat             disp0   =   state == AASlideViewControllerSlidingStateClose ? 0 : OPEN_X_POS;
    CGAffineTransform   t1      =   CGAffineTransformMakeTranslation(disp0, 0);

    self.frontViewController.view.transform =   t1;

    if (should_hide_status_bar)
    {
        [[UIApplication sharedApplication] setStatusBarHidden:is_going_to_open withAnimation:(UIStatusBarAnimationSlide)];
    }
}
completion:^(BOOL finished)
{
    self->_flags.is_sliding             =   NO;
    self.view.userInteractionEnabled    =   YES;
}];

enter image description here

eonil
  • 83,476
  • 81
  • 317
  • 516