隱藏導(dǎo)航條之后的push處理
緣由
使用ViewController內(nèi)部調(diào)用NavigationViewController的API
[self.navigationController setNavigationBarHidden:YES animated:YES];
的時候嗅虏,在界面跳轉(zhuǎn)之間巷怜,導(dǎo)航條會出現(xiàn)一下
主要是在NavigationViewController
處理
-
自定義
NavigationViewController
巾遭,如ZHMainNavigationViewController
昌渤,遵守
UIGestureRecognizerDelegate,UINavigationControllerDelegate
協(xié)議@interface ZHMainNavigationViewController ()<UIGestureRecognizerDelegate,UINavigationControllerDelegate> @end
-
自定義一個隱藏導(dǎo)航條的協(xié)議
ZHHiddenNavbar
@protocol ZHHiddenNavbar <NSObject> @end
-
實現(xiàn)如下方法
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController <UIGestureRecognizerDelegate>*)viewController animated:(BOOL)animated { //如果控制器遵守了ZHHiddenNavbar協(xié)議憨琳,則需要隱藏導(dǎo)航欄 BOOL noNav = [[viewController class] conformsToProtocol:@protocol(ZHHiddenNavbar)]; if (noNav) { //隱藏導(dǎo)航欄后會導(dǎo)致邊緣右滑返回的手勢失效邻储,需要重新設(shè)置一下這個代理 self.interactivePopGestureRecognizer.delegate = viewController; } //設(shè)置控制器是否要隱藏導(dǎo)航欄 [self setNavigationBarHidden:noNav animated:YES]; }
-
應(yīng)用
讓想要隱藏導(dǎo)航條的控制器遵守ZHHiddenNavbar
協(xié)議即可/// 英雄榜 @interface ZHTikuBrushPlanRankViewController : UIViewController<ZHHiddenNavbar> @end