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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//
// IBTUIViewController.m
// IBTImagePicker
//
// Created by Xummer on 1/17/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import "IBTUIViewController.h"
@interface IBTUIViewController ()
@end
@implementation IBTUIViewController
#pragma mark - Life Cycle
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = XXFBgColor;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (!self.navigationController) {
return;
}
NSInteger viewCtrlsCount = [self.navigationController.viewControllers count];
if (!_bNotAutoAddCancelButton &&
viewCtrlsCount == 1 &&
!self.navigationItem.leftBarButtonItems &&
[self isPresentedIn])
{
if (!_cancelButtonName) {
self.cancelButtonName = [IBTCommon localizableString:@"Cancel"];
}
[self addLeftBarBtnItemWithName:_cancelButtonName action:@selector(disMissSelf)];
}
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self addKeyboardNotification];
}
- (void)viewWillDisappear:(BOOL)animated {
[self removeKeyboardNotification];
[super viewWillDisappear:animated];
[self.view endEditing:YES];
self.navigationItem.backBarButtonItem=[self setBackBarButtonItem];
}
//设置导航条的返回按钮,在视图控制器即将消失的时候设置
- (UIBarButtonItem *)setBackBarButtonItem{
UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] init];
backButtonItem.title = @"";
return backButtonItem;
}
//收键盘操作
- (void)keyboardHidden{
}
//当点击屏幕空白处的时候,收键盘
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[self keyboardHidden];
}
//当点击键盘的return键的时候,收键盘
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[self keyboardHidden];
return YES;
}
#pragma mark - Public Method
- (void)safeSetEdgesForExtendedLayout:(UIRectEdge)extendedLayout {
if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
self.edgesForExtendedLayout = extendedLayout;
}
}
- (BOOL)isPresentedIn {
return self.presentingViewController.presentedViewController == self
|| self.navigationController.presentingViewController.presentedViewController == self.navigationController
|| [self.tabBarController.presentingViewController isKindOfClass:[UITabBarController class]];
}
- (BOOL)isPushedIn {
if ([self.navigationController.viewControllers count] > 1) {
return self != [self.navigationController.viewControllers firstObject];
}
else {
return NO;
}
}
- (void)disMissSelf {
[self.presentingViewController dismissViewControllerAnimated:YES completion:NULL];
}
#pragma mark - Route
// Below iOS6 use this method
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
// Above iOS6 use these two methods
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
#pragma mark - iOS7 Status bar
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
- (BOOL)prefersStatusBarHidden {
return NO;
}
- (BOOL)automaticallyAdjustsScrollViewInsets {
return NO;
}
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
return UIStatusBarAnimationNone;
}
- (void)updateStatueBarAppearance {
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
[self setNeedsStatusBarAppearanceUpdate];
}
}
#pragma mark - Keyboard Notification
- (void)addKeyboardNotification {
NSNotificationCenter *notiCenter = [NSNotificationCenter defaultCenter];
[notiCenter addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[notiCenter addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)removeKeyboardNotification {
NSNotificationCenter *notiCenter = [NSNotificationCenter defaultCenter];
[notiCenter removeObserver:self
name:UIKeyboardWillShowNotification
object:nil];
[notiCenter removeObserver:self
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)keyboardWillShow:(NSNotification *)note {
}
- (void)keyboardWillHide:(NSNotification *)note {
}
@end