Search code examples
iosobjective-ccocoa-touchuinavigationcontrolleruistatusbar

How do I change the colour of a UIStatusBar text during a custom transition in an animation block?


Customer taps title logo (the "a"):

enter image description here

Existing view is pushed down by new view:

enter image description here

Then to undo this the customer just taps the title logo again.

The problem I am having is that my status bar text remains black when the navigation bar and view is pushed down by the new view.

I've tried tried a few things during the animation and nothing works.

[container addSubview:move];

[UIView animateWithDuration:1 delay:0
     usingSpringWithDamping:1 initialSpringVelocity:30
                    options:0 animations:^{

                       [move setFrame: [toVC isBeingPresented] ?  endFrame : toBeginFrame];
                       [[[self navigationController] view] setFrame:CGRectMake(0, 350, 320, 640)];
                        self.navigationController.navigationBar.barStyle = UIBarStyleBlack;            // [self preferredStatusBarStyle];
                        [self setNeedsStatusBarAppearanceUpdate];


                    }

                        completion:^(BOOL finished) {

                     [transitionContext completeTransition: YES];
                 }];

Not sure how to deal with this. The black text doesn't blend well with the grey background so I need the text to turn white when the navigation bar and view is pushed down.

Would appreciate a solution thanks.

Kind regards


Solution

  • In your "to" view controller, the one with the black background, you need to implement preferredStatusBarStyle

    It should look like this:

    - (UIStatusBarStyle) preferredStatusBarStyle
    {
        return UIStatusBarStyleLightContent;
    }
    

    That should be all you need to do. When the view controller is being presented, that method will be called automatically and used to transition into the new style.