[英]iOS - Navigation bar color transition when pressing back button
在導航堆棧中使用barTintColor時,我正在嘗試更改導航欄的顏色,使用barTintColor(_:willShow:animated :)。
這是代碼:
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
if viewController is ViewerViewController {
navigationBar.barTintColor = UIColor(custom: .white)
navigationBar.tintColor = UIColor(custom: .black)
} else if viewController is FeedViewController {
navigationBar.barTintColor = UIColor(custom: .blue)
navigationBar.tintColor = UIColor(custom: .white)
}
}
當我按下視圖控制器並使用滑動后退手勢時,一切都很美妙(顏色過渡在兩個方面都很平滑)。
但是,當我按下后退按鈕時 ,顏色最初不會改變,導航過渡完成,然后顏色改變而沒有動畫 。
有人已經遇到/解決了這個問題嗎? 任何線索將不勝感激。
我有完全相同的問題,所以用自定義左欄按鈕替換了“后退”按鈕,並調用:
navigationController?.popViewController(animated: true)
編輯:
設置leftBarButton導致滑動手勢丟失,所以我需要另一個hack:
navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "back"), style: .plain, target: self, action: #selector(pop))
navigationController?.interactivePopGestureRecognizer?.delegate = self
我最終使用了KMNavigationBarTransition庫 ,它運行良好,不需要一行代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.