// EFNavigationController.h
// JueyingWeibo
//
// Created by Jueying on 15/3/4.
// Copyright (c) 2015年 MyCompany. All rights reserved.
//
@interface EFNavigationController : UINavigationController
@end
// EFNavigationController.m
// JueyingWeibo
//
// Created by Jueying on 15/3/4.
// Copyright (c) 2015年 MyCompany. All rights reserved.
//
#import "EFNavigationController.h"
@interface EFNavigationController ()
@end
@implementation EFNavigationController
當EFNavigationController這個類第一次加載的時候,只調用一次
+initialize,這個方法是當第一次給這個類發(fā)送消息時調用一次
+ (void)initialize {
// 設置導航控制器barButtonItem的title顏色
[[UIBarButtonItem appearance]
setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor
orangeColor]} forState:UIControlStateNormal];
[[UIBarButtonItem appearance]
setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor
redColor]} forState:UIControlStateHighlighted];
[[UIBarButtonItem appearance]
setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor
lightGrayColor]} forState:UIControlStateDisabled];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self leftTouchBack];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Pan gestureRecognizer
- (void)leftTouchBack {
// 獲取系統自帶滑動手勢的target對象
id target = self.interactivePopGestureRecognizer.delegate;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
#pragma clang diagnostic pop
pan.delegate = self;
[self.view addGestureRecognizer:pan];
self.interactivePopGestureRecognizer.enabled = NO;
_panGesture = pan;
// 創(chuàng)建一個成員變量座掘,可以在禁止手勢的地方直接調用_panGesture.enable = NO;來禁用手勢莺奔。
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
if (self.childViewControllers.count == 1) {
return NO;
}
return YES;
}
#pragma mark - 重寫push方法
- (void)pushViewController:(UIViewController *)viewController
animated:(BOOL)animated {
if (self.viewControllers.count > 0) {//除了根視圖控制器以外的所有控
制憔恳,以壓棧的方式push進來,就隱藏tabbar
viewController.hidesBottomBarWhenPushed = YES;
viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem
itemWithNormal:@"navigationbar_back"
highlighted:@"navigationbar_back_highlighted" target:self
action:@selector(back)];
viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem
itemWithNormal:@"navigationbar_more"
highlighted:@"navigationbar_more_highlighted" target:self
action:@selector(popToRoot)];
}
[super pushViewController:viewController animated:animated];
}
- (void)back {
[self popViewControllerAnimated:YES];
}
- (void)popToRoot {
[self popToRootViewControllerAnimated:YES];
}
@end