// 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,这个方法是当第一次给这个类发送消息时调用一次
+ (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;
// 创建一个成员变量,可以在禁止手势的地方直接调用_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
网友评论