Search code examples
iosios7ios8statusbarios7-statusbar

Reproducing Apple effects in the map app sliding the Status Bar


I am trying to replicate the effect in the Map app by which touching the map slides off and on again the top and bottom bars and the status bar along them even on iOS 7 and of course also on iOS 8 in my own app. Of course I have no problems in sliding my artifacts, but the status bar baffles me and I am not able to have it sliding on iOS 8 and much less on iOS 7. The best I may attain is to have it fading by overriding prefersStatusBarHidden; what does not of course go well with the general sliding movement.

How is it possible to do it instead?


Solution

  • This is my final implementation for the control thanks to Tommy's hint:

    BOOL controlsWereShown=YES;
    
    -(void)toggleControls{
        UIWindow *statusBarWindow = (UIWindow *)[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"];
        CGRect frame=CGRectZero;
        if([statusBarWindow isKindOfClass:[UIWindow class]]){
            frame= statusBarWindow.frame;
            if(frame.origin.y < 0){
                frame.origin.y = 0;
            }
            else{
                frame.origin.y = -85;
            }
         }
        [UIView animateWithDuration:.8 animations:^{
             self.barConstraint.constant=(controlsWereShown?-85:19);
             self.bottomConstraint.constant=(controlsWereShown?50:0);
             self.renewalViewConstraint.constant=(controlsWereShown?-120:0);
             controlsWereShown=!controlsWereShown;
             if (frame.size.width != 0) statusBarWindow.frame = frame;
             [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate) withObject:nil];
             [self.view layoutIfNeeded];
         }
                    completion :^(BOOL finished){
    
                    }
         ];
    }
    

    The only problem in that solution is that the status bar slides together with the top bar instead of remaining attached on the top of it while sliding. I sort of fixed it by setting the end origin at -85 instead of -20, so to follow the bar while sliding.