接受的答案有一個問題給我。
我的應用程序的導航深度爲三個UIViewController。
- FirsViewController顯示的是UITabBar。(正確)
- FirsViewController推送SecondViewController,並且SecondViewController不顯示UITabBar。 (正確)
- SecondViewController推送ThirdViewController,ThirdViewController顯示的是UITabBar。 (不正確)
- ThirdViewController彈出到SecondViewController,SecondViewController顯示的是UITabBar。 (不正確)
- SecondViewController彈出到FirstViewController,FirstViewController顯示的是UITabBar。 (正確)
對我來說是設置UINavigationControllerDelegate的代表解決方案
迅速:
self.navigationController?.delegate = self
的Objective-C:
self.navigationController.delegate = self;
,然後實現以下的委託方法
斯威夫特:
fun navigationController(navigationController: UINavigationController, animationControllerForOperation operation: UINavigationControllerOperation, fromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if fromVC.isKindOfClass(FirstViewController) && toVC.isKindOfClass(SecondViewController) {
self.hidesBottomBarWhenPushed = true;
}
else if fromVC.isKindOfClass(SecondViewController) && toVC.isKindOfClass(FirstViewController) {
self.hidesBottomBarWhenPushed = false;
}
return nil
}
的Objective-C:
-(id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController*)fromVC
toViewController:(UIViewController*)toVC
{
if ([fromVC isKindOfClass:[FirstViewController class]] && [fromVC isKindOfClass:[SecondViewController class]]) {
self.hidesBottomBarWhenPushed = true;
}
else if ([fromVC isKindOfClass:[SecondViewController class]] && [fromVC isKindOfClass:[FirstViewController class]]) {
self.hidesBottomBarWhenPushed = false;
}
return nil;
}
希望它幫助。
我正面臨着同樣的問題,謝謝你! – Mateus 2012-11-18 02:22:01