UIStatusBar在Facebook新推出的iOS7应用程序中 [英] UIStatusBar as in Facebook new iOS7 application

查看:100
本文介绍了UIStatusBar在Facebook新推出的iOS7应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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.

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

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.

我也使用了这段代码:

- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
    return UIStatusBarAnimationFade;
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

- (BOOL)prefersStatusBarHidden
{
    return NO;
}

提前致谢。

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

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

更新: @yoeriboven回答这个问题的解决办法是将2个视图放在 SWRevealViewController 的顶部,黑色和蓝色,只是为两个设置动画,这是一个很好的解决方案,它工作得很好。

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.

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

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];

现在,如果您使用 SWRevealViewController ,您可以使用下一个代码,如果没有,只需自己构建,在 SWRevealViewController.m 只需 #importAppDelegate.h而不是用这个替换 touchesMoved 方法:

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;
    }
}

现在稍微下去并搜索方法 rightRevealToggleAnimated 并将其替换为:

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];
}

应该这样做,享受!

推荐答案

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

In iOS 7, your view controllers' view is full screen. So you could just put two views on top of each other at the top 22 px (status bar height) of the view. The bottom one black and the top one the same color as your navigation bar. When swiping to the SWRevealViewController, with one of the UIScrollView delegate methods you can calculate how far it is in percentages and apply that value to the opacity of the subview with your navigation bar's color.

这篇关于UIStatusBar在Facebook新推出的iOS7应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆