#import <UIKit/UIKit.h>
@interface BaseViewController : UIViewController
/*水印图片*/
@property (nonatomic,strong) UIView *waterMarkBgView;
@property (nonatomic,strong) UIView *sepView1;
@property (nonatomic,strong) UIView *sepView2;
@property (nonatomic,strong) UIView *sepView3;
//返回操作
- (void)backBtnAction;
//添加/删除键盘通知
- (void)addKeyBoardNoticefication;
- (void)removeKeyBoardNoticefication;
- (void)keyBoardAddSureButtonTextField:(UITextField *)textField showPoint:(BOOL)show;
- (void)keyBoardAddSureButtonTextView:(UITextView *)textView;
- (void)resignButtonClick:(UIButton *)button;
//加载菊花
- (void)showHUD;
//隐藏菊花
- (void)hideHUD;
//显示登录控制器
- (void)showLoginViewController;
@end
#import "BaseViewController.h"
@interface BaseViewController (){
UIView *_keyboardTopView;
}
@property (nonatomic,strong)UIButton *resignButton;
@property (nonatomic,strong)UITextField *currentTextField;
@property (nonatomic, strong) UITextView *currentTextView;
@end
@implementation BaseViewController
#pragma mark - Life Cycle
- (void)dealloc
{
NSLog(@"%@销毁了、、",self);
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.navigationBar.hidden = NO;
//DLog(@"%@将要出现",self);
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
//DLog(@"%@将要消失",self);
[self hideHUD];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = colorForMainBgColor;
if ([Device isIOS7orLater])
{
self.edgesForExtendedLayout = UIRectEdgeNone;
}
if (self.navigationController.viewControllers.count > 1) {
[self.navigationItem setLeftItemWithTarget:self action:@selector(backBtnAction) image:[UIImage imageNamed:@"common_back_btn"]];
}
}
#pragma mark - Event
- (void)backBtnAction
{
[self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - keyBoard Num
- (void)keyBoardAddSureButtonTextField:(UITextField *)textField showPoint:(BOOL)show{
self.currentTextField = textField;
if (_keyboardTopView == nil) {
_keyboardTopView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 40)];
_keyboardTopView.backgroundColor = RGBColor(205, 205, 205);
//
UIButton *resignButton = [UIButton buttonWithType:UIButtonTypeCustom];
resignButton.frame = CGRectMake(0, 0, 60, 40);
[resignButton addTarget:self action:@selector(resignButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[resignButton setTitle:@"确定" forState:UIControlStateNormal];
[resignButton setTitleColor:RGBColor(255, 255, 255) forState:UIControlStateNormal];
[resignButton setTitleColor:colorForRedOther forState:UIControlStateHighlighted];
// resignButton.showsTouchWhenHighlighted = YES;
[_keyboardTopView addSubview:resignButton];
}
textField.inputAccessoryView = _keyboardTopView;
//数字键盘 问题
}
- (void)keyBoardAddSureButtonTextView:(UITextView *)textView{
self.currentTextView = textView;
if (_keyboardTopView == nil) {
_keyboardTopView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 40)];
_keyboardTopView.backgroundColor = RGBColor(205, 205, 205);
//
UIButton *resignButton = [UIButton buttonWithType:UIButtonTypeCustom];
resignButton.frame = CGRectMake(0, 0, 60, 40);
[resignButton addTarget:self action:@selector(resignButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[resignButton setTitle:@"确定" forState:UIControlStateNormal];
[resignButton setTitleColor:RGBColor(255, 255, 255) forState:UIControlStateNormal];
[resignButton setTitleColor:colorForRedOther forState:UIControlStateHighlighted];
// resignButton.showsTouchWhenHighlighted = YES;
[_keyboardTopView addSubview:resignButton];
}
textView.inputAccessoryView = _keyboardTopView;
//数字键盘 问题
}
//确定移除
- (void)resignButtonClick:(UIButton *)button{
if (_resignButton.superview){
//隐藏完成按钮
_resignButton.hidden = YES;
//从视图中移除掉
[_resignButton removeFromSuperview];
_resignButton = nil;
}
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];//关闭键盘
}
//添加键盘出现通知
- (void)addKeyBoardNoticefication
{
//注册键盘出现 消失通知
[NotificationCenter addObserver:self
selector:@selector(keyBoardWillShow:)
name:UIKeyboardWillShowNotification object:nil];
[NotificationCenter addObserver:self
selector:@selector(keyBoardWillHide:)
name:UIKeyboardWillHideNotification object:nil];
}
- (void)removeKeyBoardNoticefication
{
//注册键盘出现 消失通知
[NotificationCenter removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[NotificationCenter removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
//键盘出现
- (void)keyBoardWillShow:(NSNotification *)notification{}
//键盘消失
- (void)keyBoardWillHide:(NSNotification *)notification{}
- (void)showHUD
{
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
}
- (void)hideHUD
{
// [MBProgressHUD hideHUDForView:self.view animated:YES];
NSArray *hudSunViews =[MBProgressHUD allHUDsForView:self.view];
for(MBProgressHUD *view in hudSunViews){
[view removeFromSuperview];
}
}
- (void)showLoginViewController
{
}
- (UIView *)waterMarkBgView
{
if (!_waterMarkBgView) {
UIImage *waterMarkImg = [UIImage imageNamed:@"common_waterMark1"];
UIColor *colorForImg = [[UIColor alloc] initWithPatternImage:waterMarkImg];
_waterMarkBgView =[UIView viewWithFrame:self.view.bounds backgroundColor:colorForImg];
_waterMarkBgView.userInteractionEnabled = NO;
}
return _waterMarkBgView;
}
- (UIView *)sepView1{
if (!_sepView1) {
_sepView1 =[UIView viewWithFrame:CGRectMake(0, 0, kScreenWidth, 10) backgroundColor:colorForMainBgColor];
}
return _sepView1;
}
- (UIView *)sepView2{
if (!_sepView2) {
_sepView2 =[UIView viewWithFrame:CGRectMake(0, 0, kScreenWidth, 10) backgroundColor:colorForMainBgColor];
}
return _sepView2;
}
- (UIView *)sepView3{
if (!_sepView3) {
_sepView3 =[UIView viewWithFrame:CGRectMake(0, 0, kScreenWidth, 10) backgroundColor:colorForMainBgColor];
}
return _sepView3;
}
@end
网友评论