-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBaseNavigationViewController.m
92 lines (75 loc) · 2.92 KB
/
BaseNavigationViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*********************************************************************
* 版权所有 magic_Zzz
*
* 文件名称: BaseNavigationViewController 基础navigation
* 内容摘要: 基础抽屉
* 其它说明: 实现文件
* 作 成 者: ZGD
* 完成日期: 2016年03月08日
* 修改记录1:
* 修改日期:
* 修 改 人:
* 修改内容:
* 修改记录2:
**********************************************************************/
#import "BaseNavigationViewController.h"
#import "Common.h"
#import "UIViewController+BackButtonHandler.h"
@interface BaseNavigationViewController ()<UINavigationControllerDelegate>
@end
@implementation BaseNavigationViewController
- (id)initWithRootViewController:(UIViewController *)rootViewController
{
self = [super initWithRootViewController:rootViewController];
// self.navigationController.interactivePopGestureRecognizer.delegate = (id)self
[self.navigationBar setBarTintColor:ZZZRGB(147, 2, 138)];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];
self.navigationBar.tintColor = [UIColor whiteColor];
self.navigationBar.translucent = NO;
[self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]
}];
return self;
}
-(UIImage *)imageWithColor:(UIColor *)color{
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext(); return image;
}
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem*)item {
if([self.viewControllers count] < [navigationBar.items count]) {
return YES;
}
BOOL shouldPop = YES;
UIViewController* vc = [self topViewController];
if([vc respondsToSelector:@selector(navigationShouldPopOnBackButton)]) {
shouldPop = [vc navigationShouldPopOnBackButton];
}
if(shouldPop) {
dispatch_async(dispatch_get_main_queue(), ^{
[self popViewControllerAnimated:YES];
});
} else {
// Workaround for iOS7.1. Thanks to @boliva - http://stackoverflow.com/posts/comments /34452906
for(UIView *subview in [navigationBar subviews]) {
if(subview.alpha < 1.) {
[UIView animateWithDuration:.25 animations:^{
subview.alpha = 1.;
}];
}
}
}
return NO;
}
- (void)viewDidLoad {
[super viewDidLoad];
// self.delegate = self;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end