I have an app with side bar menu, kinda like Facebook side bar menu. I'm using this class called SWRevealViewController
and it's working great. Now since iOS7 has came out, I just can't figure out how to adjust my Status and Navigation Bar to be like in Facebook app.
As you can see, in the Facebook app, when the user slides the screen and open's the menu, the status bar turn from the Navigation Bar blue color to black with Fade animation. In my app, the user slides the screen to open the menu and the status bar with the blue color (that is blue because of that view NavigationBar) won't fade away and change the color into black.
Also, another issue that I'm having, I just can't change the StatusBar text color to white. I've tried everything, every piece of code on the internet, read all apple's documentation, but still couldn't manage to change the color.
I also used this code:
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
return UIStatusBarAnimationFade;
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
- (BOOL)prefersStatusBarHidden
{
return NO;
}
Thanks in advance.
========================================================================
UPDATE: The solution to this problem as in @yoeriboven answer is to put 2 views on top of the SWRevealViewController
with black color and blue color and just animate the two, this is a great solution and it worked just great.
So, when creating the revealController I've created 2 blank UIViews and added them, one blue and one black. One of them, the black one, I kept hidden for now.
self.revealController = [[SWRevealViewController alloc] initWithRearViewController:nil frontViewController:self.frontViewController];
self.revealController.delegate = self;
self.appDelegate.window.rootViewController = self.revealController;
self.statusBarBlack = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.appDelegate.window.frame.size.width, 20)];
[self.statusBarBlack setBackgroundColor:[UIColor blackColor]];
self.statusBarBlue = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.appDelegate.window.frame.size.width, 20)];
[self.statusBarBlue setBackgroundColor:[UIColor blueColor]];
[self.appDelegate.window.rootViewController.view addSubview:self.statusBarBlack];
[self.appDelegate.window.rootViewController.view addSubview:self.statusBarBlue];
Now if you are using SWRevealViewController
you can use the next code, if not, just build it on your own, inside SWRevealViewController.m
just #import "AppDelegate.h"
and than replace the touchesMoved
method with this one:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
if (self.state == UIGestureRecognizerStateFailed)
return;
// Change color of status bar by the location of your swipe
AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
UITouch *currentTouch = [touches anyObject];
CGPoint currentTouchLocationOnWindow = [currentTouch locationInView:appDelegate.window];
appDelegate.splashScreen.blueStatusBar.alpha = currentTouchLocationOnWindow.x / appDelegate.window.frame.size.width;
if ( _dragging )
return;
const int kDirectionPanThreshold = 5;
UITouch *touch = [touches anyObject];
CGPoint nowPoint = [touch locationInView:self.view];
CGFloat moveX = nowPoint.x - _init.x;
CGFloat moveY = nowPoint.y - _init.y;
if (abs(moveX) > kDirectionPanThreshold)
{
if (_direction == SWDirectionPanGestureRecognizerHorizontal)
_dragging = YES;
else
self.state = UIGestureRecognizerStateFailed;
}
else if (abs(moveY) > kDirectionPanThreshold)
{
if (_direction == SWDirectionPanGestureRecognizerVertical)
_dragging = YES ;
else
self.state = UIGestureRecognizerStateFailed;
}
}
Now go down a little bit and search for the method rightRevealToggleAnimated
and replace her with this one:
- (void)rightRevealToggleAnimated:(BOOL)animated
{
FrontViewPosition toogledFrontViewPosition = FrontViewPositionLeft;
if (_frontViewPosition >= FrontViewPositionLeft) {
toogledFrontViewPosition = FrontViewPositionLeftSide;
[UIView animateWithDuration:0.3 animations:^{
// Change color of status bar
AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
appDelegate.splashScreen.blueStatusBar.alpha = 0.0;
}];
} else {
[UIView animateWithDuration:0.3 animations:^{
// Change color of status bar
AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
appDelegate.splashScreen.blueStatusBar.alpha = 1.0;
}];
}
[self setFrontViewPosition:toogledFrontViewPosition animated:animated];
}
That should do the trick, enjoy!