2013-10-09 28 views
6

是否有任何方式以具有不同的在不同的推控制器與平滑的顏色過渡動畫UINavigationControllerUINavigationBarbarTintColor的iOS 7的UINavigationController的NavBar控制器彩色動畫

我想有「期間UINavigationController小號色調顏色的壓入/彈出動畫並且理想地還交互式彈出(基於姿勢控制器彈出)UINavigationBar的平滑的動畫。

爲什麼我需要這個?我想在導航堆棧中有1個控制器具有不同的色調顏色,指示某些任務的狀態(紅色/綠色等)。

我迄今爲止嘗試:

  • viewWillAppear(查看生命週期)的方法,但沒有辦法動畫barTintColor(如setBarTintColor:animated:
  • [UIView animation...]塊改變barTintColor,但只是奇怪地動畫框(可能)一些背景層而不是平滑的顏色過渡。
  • 要更改barTintColor[UIView transitionWithView:...]塊與UIViewAnimationOptionTransitionCrossDissolve,但這並不影響變化。在動畫持續時間後立即改變爲新的色調顏色
  • 我有一個想法實現新的iOS 7自定義過渡計算和改變導航過程中的顏色,但這似乎是大矯枉過正(特別是如果我想保留原始動畫外觀無處不在)

謝謝大家的任何想法和答案

+0

你有沒有找到一個解決方案? – jpsim

+0

不幸的是,我沒有:-( –

+1

嘗試在_all_視圖控制器中設置'viewWillAppear'方法中的'barTintColor'。當barTintColor只在第二個控制器中設置時,我遇到了這個問題。色調的顏色是平滑的動畫(雖然沒有測試交互轉換) – skozin

回答

26

您可以通過使用UIViewControllerTransitionCoordinator得到這個。

  1. 將示例代碼複製到AController並自定義顏色。
  2. 將示例代碼複製到BController並自定義顏色。
  3. 就是這樣!在UINavigationController的推/換過程中,AController的風格將平滑淡入/淡出至BController的風格。

示例代碼:

-(void) viewWillAppear:(BOOL)animated{ 
    [super viewWillAppear:animated]; 

    [[self transitionCoordinator] animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) { 
     self.navigationController.navigationBar.translucent = NO; 
     self.navigationController.navigationBar.barStyle = UIBarStyleDefault; 

     // text color 
     [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}]; 

     // navigation items and bar button items color 
     self.navigationController.navigationBar.tintColor = [UIColor whiteColor]; 

     // background color 
     self.navigationController.navigationBar.barTintColor = [UIColor blueColor]; 
    } completion:nil]; 
} 
+0

你會如何做IOS6? – Toad