2017-07-03 42 views
1

可以說,我有3個視圖控制器:AB,C,全部嵌入到導航控制器中。 AB有一個導航欄,C沒有。交互式轉換:導航欄外觀問題

我有一個自定義的BC之間的交互轉換。因爲我需要我的導航欄上C消失了,我實現的UINavigationControllerDelegate此功能:

func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) { 
    if viewController is C { 
     navigationController.setNavigationBarHidden(true, animated: animated) 
    } 
    else { 
     navigationController.setNavigationBarHidden(false, animated: animated) 
    } 
} 

一切完美的作品在常見的場景,當我只能讓推抵扣的轉變。

但是,當我取消過渡B - 通過我的UIPercentDrivenInteractiveTransition調用cancel()>C,在導航欄上不B露面。在這裏,我必須撥打setNavigationBarHidden(false, ...),但我沒有設法找到正確的位置。

如果我把它在BviewWillAppear,出現導航欄,但看起來真的很奇怪 - 它包含它是否有導航欄上的C必須的元素。如果我彈回到A,它會閃爍片刻並顯示預期的內容,但在轉換後立即將A導航欄替換爲B導航欄!

所以,好像導航欄棧後B不知何故破 - >C過渡消除,這似乎是相對轉移到viewcontrollers這樣的:

     has 
----------------------------------------------- 
| ViewController | Navigation bar of | 
----------------------------------------------- 
|   A   |   B   | 
----------------------------------------------- 
|   B   |   C   | 
----------------------------------------------- 

所以,我的問題是,什麼是正確的在這種情況下撥打navigationController.setNavigationBarHidden(false, animated: true)的地方?

回答

1

嗯,我設法找到了一個醜陋的黑客攻擊由我自己來解決它。也許在這個世界上有人會覺得有幫助。

  • 在我的自定義UIPercentDrivenInteractiveTransition我重寫cancel函數那樣:

    class CustomTransitionManager: UIPercentDrivenInteractiveTransition { 
    
        /// Indicates transition direction. Must be set before each transition. 
        var forward: Bool = true 
    
        /// Current navigation controller used for transition. Must be set before transition starts 
        var nc: UINavigationController? 
    
        /** 
        * Hack #1 with UINavigationController here 
        */ 
        override func cancel() { 
         super.cancel() 
    
         if forward { 
          self.nc?.setNavigationBarHidden(false, animated: false) 
         } 
         self.nc?.setNavigationBarHidden(forward, animated: false) 
        } 
    } 
    
  • 在每個視圖控制器的(A,B,C)我提出以下劈:

    override func viewWillAppear(_ animated: Bool) { 
        super.viewWillAppear(animated) 
    
        // Hide and immediately show navigation bar: this will restore it's correct state 
        self.navigationController?.setNavigationBarHidden(true, animated: false) 
        self.navigationController?.setNavigationBarHidden(false, animated: true) 
    } 
    

最好的解決方案可能會是012一個模式全屏演示,但在我的情況下,我正在處理一個已經損壞導航層次結構的項目,而我沒有時間正確地修復它。基本上,這就是我遇到這個問題的原因。