0

Example project: http://cl.ly/0O2t051o081p

I want to achieve a slide-out sidebar as described in this question where the status bar moves as well. I've got everything working and the sidebar slides, but as soon as I try to hide the status bar with to complete the "illusion" it stops anything from happening at all and the sidebar no longer slides out.

Here's my code:

- (void)viewDidAppear:(BOOL)animated {
    double delayInSeconds = 1.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [self.PostsView addSubview:[[UIScreen mainScreen] snapshotViewAfterScreenUpdates:NO]];

        hide = YES;
        [self setNeedsStatusBarAppearanceUpdate];

        [UIView animateWithDuration:1.0 animations:^{
            CGRect postsFrame = self.PostsView.frame;
            postsFrame.origin.x = self.MenuView.frame.size.width;

            self.PostsView.frame = postsFrame;
        }];
    });
}

Where my code basically consists of a containing view controller that contains two child view controllers (the main view controller and the sidebar view controller) built in the Storyboard.

I've also tried setting View controller-based status bar appearance in the plist to NO and calling [[UIApplication sharedApplication] setStatusBarHidden] but the exact same result happens where it breaks.

What am I doing wrong?

Community
  • 1
  • 1
Doug Smith
  • 27,683
  • 54
  • 189
  • 363

1 Answers1

1

I'm not sure why that line breaks you animation, but it worked properly if I did what you said in your last paragraph, but added a layoutIfNeeded to the view before the animation (I did set View controller-based status bar appearance to NO in the info.plist).

- (void)viewDidAppear:(BOOL)animated {
    double delayInSeconds = 1.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [self.PostsView addSubview:[[UIScreen mainScreen] snapshotViewAfterScreenUpdates:NO]];
        [[UIApplication sharedApplication] setStatusBarHidden:YES];
        [self.view layoutIfNeeded];
        hide = YES;
        [UIView animateWithDuration:1.0 animations:^{
            CGRect postsFrame = self.PostsView.frame;
            postsFrame.origin.x = self.MenuView.frame.size.width;

            self.PostsView.frame = postsFrame;
        }];
    });
}

Also it's unnecessary to implement prefersStatusBarHidden.

rdelmar
  • 102,832
  • 11
  • 203
  • 218
  • Why is layoutIfNeeded required? – Doug Smith Dec 12 '13 at 22:20
  • 1
    @DougSmith, I think it hides the status bar immediately, so it's hiding doesn't interfere with he animation. Under some conditions, one animation will cancel another animation -- that seems to be happening here. – rdelmar Dec 12 '13 at 22:26