Facebook 新 iOS7 应用程序中的 UIStatusBar

2023-11-27

我有一个带有侧栏菜单的应用程序,有点像 Facebook 侧栏菜单。我正在使用这个名为SWRevealViewController而且效果很好。现在自从 iOS7 发布以来,我就是不知道如何调整我的状态和导航栏,就像在 Facebook 应用程序中一样。

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

facebook app navigation bar

my app navigation bar

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

我也使用了这段代码:

- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
    return UIStatusBarAnimationFade;
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

- (BOOL)prefersStatusBarHidden
{
    return NO;
}

提前致谢。

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

UPDATE:这个问题的解决方案如 @yoeriboven 答案所示,是将 2 个视图放在SWRevealViewController使用黑色和蓝色,然后将两者动画化,这是一个很好的解决方案,而且效果很好。

因此,在创建 RevealController 时,我创建了 2 个空白 UIView 并添加了它们,一蓝一黑。其中一张,黑色的,我暂时藏起来了。

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

现在再往下一点,搜索一下方法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];
}

这应该可以解决问题,享受吧!


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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Facebook 新 iOS7 应用程序中的 UIStatusBar 的相关文章

随机推荐