我有一個側欄菜單的應用程序,有點像Facebook側欄菜單。我正在使用這個名爲SWRevealViewController
的課程,它工作得很好。現在自iOS7出來後,我只是無法弄清楚如何調整我的狀態和導航欄,就像在Facebook應用程序。UIStatusBar在Facebook新的iOS7應用程序
正如您所看到的,在Facebook應用中,當用戶滑動屏幕並打開菜單時,狀態欄將通過淡入淡出動畫從導航欄藍色變爲黑色。在我的應用程序中,用戶滑動屏幕以打開菜單,狀態欄上的藍色(由於該視圖的NavigationBar而呈藍色)不會消失並將顏色更改爲黑色。
同樣,我有另外一個問題,我只是不能在狀態欄的文本顏色更改爲白色。我已經嘗試過所有的東西,互聯網上的每一段代碼,閱讀所有蘋果的文檔,但仍然無法設法改變顏色。
我也用這個代碼:
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
return UIStatusBarAnimationFade;
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
- (BOOL)prefersStatusBarHidden
{
return NO;
}
在此先感謝。
============================================== ==========================
UPDATE:在@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];
現在,如果你正在使用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;
}
}
現在往下走一點點,尋找方法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];
}
這應該做的伎倆,享受!
更改狀態欄樣式時,不要忘記在呈現的視圖控制器上調用'setNeedsStatusBarAppearanceUpdate'。 –
我在調用viewDidLoad方法時仍然是這樣。 –
我不確定這是否正確。嘗試viewDidAppear。 –