#import <UIKit/UIKit.h>
@interface ZJBaseNaviController : UINavigationController
@end
#import "ZJBaseNaviController.h"
#import "UIViewController+BackButtonHandler.h"
@interface ZJBaseNaviController ()<UIGestureRecognizerDelegate>
@end
@implementation ZJBaseNaviController
#pragma mark - 初始化
/**
只加载一次
*/
+(void)load{
UINavigationBar *navBar = [UINavigationBar appearance];
// 导航栏颜色
navBar.barTintColor = [UIColor whiteColor];
// 导航栏是否有透明效果
navBar.translucent = NO;
// 导航栏分割线
navBar.shadowImage = [UIImage new];
// 导航栏字体颜色
NSMutableDictionary * param = [NSMutableDictionary new];
[param setObject:[UIFont systemFontOfSize:17] forKey:NSFontAttributeName];
[param setObject:[UIColor redColor] forKey:NSForegroundColorAttributeName];
[navBar setTitleTextAttributes:param];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
// 滑动手势
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.interactivePopGestureRecognizer.delegate = self;
}
}
#pragma mark - UIGestureRecognizerDelegate
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
//是否出发手势
return self.childViewControllers.count > 1;
}
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
if(self.childViewControllers.count>0){
viewController.navigationController.title = @"";
viewController.hidesBottomBarWhenPushed = YES;
CGRect tempFrame = CGRectMake(0, 0, 40, 40);
UIButton * button = [[UIButton alloc] initWithFrame:tempFrame];
[button setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 10)];
[button setImage:[UIImage imageNamed:@"arrow_left"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(backBeforViewController) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithCustomView:button];
viewController.navigationItem.leftBarButtonItem = leftItem;
}
[super pushViewController:viewController animated:animated];
}
-(void)backBeforViewController{
BOOL shouldPop = YES;
UIViewController * tempViewController = [self topViewController];
if([tempViewController respondsToSelector:@selector(navigationShouldPopOnBackButton)]) {
shouldPop = [tempViewController navigationShouldPopOnBackButton];
}
if(shouldPop){
[self popViewControllerAnimated:YES];
}
}
@end