UIStatusBar在Facebook新的iOS7应用程序

我有一个侧栏菜单的应用程序,有点像Facebook侧栏菜单。 我正在使用这个名为SWRevealViewController类,它工作的很好。 现在iOS7已经出来,我只是不知道如何调整我的状态和导航栏像在Facebook应用程序。

正如你所看到的,在Facebook应用程序中,当用户滑动屏幕并打开菜单时,状态栏将通过淡入淡出animation从导航栏蓝色变为黑色。 在我的应用程序中,用户滑动屏幕以打开菜单和状态栏与蓝色(这是因为该视图NavigationBar蓝色)不会消失,并将颜色变成黑色。

Facebook应用程序导航栏

我的应用程序导航栏

此外,我有另一个问题,我只是不能将StatusBar文本颜色更改为白色。 我已经尝试了所有的东西,互联网上的所有代码,阅读所有苹果的文档,但仍然无法设法改变颜色。

我也用这个代码:

 - (UIStatusBarAnimation)preferredStatusBarUpdateAnimation { return UIStatusBarAnimationFade; } - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; } - (BOOL)prefersStatusBarHidden { return NO; } 

提前致谢。

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

更新 :这个问题的解决scheme在@yoeriboven答案是放在SWRevealViewController与黑色和蓝色的顶部2视图,只是animation两个,这是一个很好的解决scheme,它的工作很好。

所以,在创buildrevealController时,我创build了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]; 

现在,如果您正在使用SWRevealViewController ,则可以使用下一个代码,如果没有,只需在SWRevealViewController.m自行构build它,只需#import "AppDelegate.h"然后用下面的代码replacetouchesMoved方法:

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

现在下来一点,search方法rightRevealToggleAnimated并用这个replace她:

 - (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像素(状态栏高度)上放置两个视图。 底部的黑色和顶部的颜色与导航栏相同。 使用UIScrollView委托方法之一滑动到SWRevealViewController ,可以计算它以百分比表示的距离,并使用导航栏的颜色将该值应用于子视图的不透明度。

我有另一种像魅力一样工作的方法。

首先在SWRevealView类的SWRevealViewController.h中创build一个名为underStatusBarViewView @property underStatusBarView ,将其置于状态栏位置。

然后在- (id)initWithFrame:(CGRect)frame controller:(SWRevealViewController*)controller方法我实例化- (id)initWithFrame:(CGRect)frame controller:(SWRevealViewController*)controller设置其颜色为黑色,其alpha为0。

 - (id)initWithFrame:(CGRect)frame controller:(SWRevealViewController*)controller { self = [super initWithFrame:frame]; if ( self ) { _c = controller; CGRect bounds = self.bounds; _frontView = [[UIView alloc] initWithFrame:bounds]; _frontView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; [self addSubview:_frontView]; CALayer *frontViewLayer = _frontView.layer; frontViewLayer.masksToBounds = NO; frontViewLayer.shadowColor = [UIColor blackColor].CGColor; /* Here starts my under status bar implementation */ CGRect statusFrame = [[UIApplication sharedApplication]statusBarFrame]; _underStatusBarView = [[UIView alloc]initWithFrame:statusFrame]; [_underStatusBarView setBackgroundColor:[UIColor blackColor]]; [_underStatusBarView setAlpha:0.0]; [self addSubview:_underStatusBarView]; /* here it ends */ //frontViewLayer.shadowOpacity = 1.0f; frontViewLayer.shadowOpacity = _c.frontViewShadowOpacity; frontViewLayer.shadowOffset = _c.frontViewShadowOffset; frontViewLayer.shadowRadius = _c.frontViewShadowRadius; } return self; } 

然后我将一行代码添加到负责布置后视图的私有方法- (void)_layoutRearViewsForLocation:(CGFloat)xLocation根据前视图位置更改_underStatusBarView alpha。

 - (void)_layoutRearViewsForLocation:(CGFloat)xLocation { CGRect bounds = self.bounds; CGFloat rearRevealWidth = _c.rearViewRevealWidth; if ( rearRevealWidth < 0) rearRevealWidth = bounds.size.width + _c.rearViewRevealWidth; CGFloat rearXLocation = scaledValue(xLocation, -_c.rearViewRevealDisplacement, 0, 0, rearRevealWidth); CGFloat rearWidth = rearRevealWidth + _c.rearViewRevealOverdraw; _rearView.frame = CGRectMake(rearXLocation, 0.0, rearWidth, bounds.size.height); CGFloat rightRevealWidth = _c.rightViewRevealWidth; if ( rightRevealWidth < 0) rightRevealWidth = bounds.size.width + _c.rightViewRevealWidth; CGFloat rightXLocation = scaledValue(xLocation, 0, _c.rightViewRevealDisplacement, -rightRevealWidth, 0); CGFloat rightWidth = rightRevealWidth + _c.rightViewRevealOverdraw; _rightView.frame = CGRectMake(bounds.size.width-rightWidth+rightXLocation, 0.0f, rightWidth, bounds.size.height); /*this line changes the under status bar view alpha*/ _underStatusBarView.alpha = xLocation/rearRevealWidth; } 

你如何使用rightRevealView你应该改变rearRevealWidhtrightRevealWidth只是为了防止未来的兼容性问题。

我真的很喜欢你的方法。 我已经做了几个更新你的代码,并希望将其提交给项目。 如果您有任何问题,请告诉我。