UIStatusBar在Facebook新推出的iOS7应用程序中

Yos*_*far 6 objective-c uinavigationbar ios uistatusbar ios7

我有一个侧栏菜单的应用程序,有点像Facebook边栏菜单.我正在使用这个被调用的类SWRevealViewController,它工作得很好.现在自iOS7问世以来,我无法弄清楚如何调整我的状态和导航栏就像在Facebook应用程序中一样.

如您所见,在Facebook应用程序中,当用户滑动屏幕并打开菜单时,状态栏会从导航栏蓝色变为黑色,并带有淡入淡出动画.在我的应用程序中,用户滑动屏幕以打开菜单,状态栏的蓝色(由于该视图NavigationBar而为蓝色)不会消失并将颜色更改为黑色.

Facebook app导航栏

我的app导航栏

另外,我有另一个问题,我只是无法将StatusBar文本颜色更改为白色.我已经尝试了所有内容,互联网上的每一段代码,都阅读了所有苹果的文档,但仍然无法改变颜色.

我也用过这段代码:

- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
    return UIStatusBarAnimationFade;
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

- (BOOL)prefersStatusBarHidden
{
    return NO;
}
Run Code Online (Sandbox Code Playgroud)

提前致谢.

================================================== ======================

更新:@yoeriboven回答中的这个问题的解决方案是将2个视图放在SWRevealViewController黑色和蓝色的顶部,只是为两个设置动画,这是一个很好的解决方案,它的效果非常好.

因此,在创建revealController时,我创建了2个空白UIViews并添加了它们,一个蓝色和一个黑色.其中一个是黑色的,我现在一直隐藏着.

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];
Run Code Online (Sandbox Code Playgroud)

如果您使用的是现在,SWRevealViewController你可以使用下面的代码,如果没有,就建立它自己的,里面SWRevealViewController.m只是#import "AppDelegate.h"比更换touchesMoved与此一方法:

- (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;
    }
}
Run Code Online (Sandbox Code Playgroud)

现在再往前走一点,然后搜索一下这个方法rightRevealToggleAnimated并用以下方法替换她:

- (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];
}
Run Code Online (Sandbox Code Playgroud)

这应该做的伎俩,享受!

yoe*_*ven 7

在iOS 7中,视图控制器的视图是全屏的.因此,您可以在视图的前22个px(状态栏高度)处将两个视图放在彼此的顶部.底部一个黑色,顶部一个颜色与导航栏相同.当SWRevealViewController使用其中一种UIScrollView委托方法滑动时,您可以计算它的百分比范围,并使用导航栏的颜色将该值应用于子视图的不透明度.