BaseViewController基類

#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(@"%@將要出現(xiàn)",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;
    //數(shù)字鍵盤 問題
}

- (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;
    //數(shù)字鍵盤 問題
}

//確定移除
- (void)resignButtonClick:(UIButton *)button{
    if (_resignButton.superview){
        //隱藏完成按鈕
        _resignButton.hidden = YES;
        //從視圖中移除掉
        [_resignButton removeFromSuperview];
        _resignButton = nil;
    }
    
    [[[UIApplication sharedApplication] keyWindow] endEditing:YES];//關(guān)閉鍵盤
}

//添加鍵盤出現(xiàn)通知
- (void)addKeyBoardNoticefication
{
    //注冊鍵盤出現(xiàn) 消失通知
    [NotificationCenter addObserver:self
                             selector:@selector(keyBoardWillShow:)
                                 name:UIKeyboardWillShowNotification object:nil];
    
    [NotificationCenter addObserver:self
                             selector:@selector(keyBoardWillHide:)
                                 name:UIKeyboardWillHideNotification object:nil];
}

- (void)removeKeyBoardNoticefication
{
    //注冊鍵盤出現(xiàn) 消失通知
    [NotificationCenter removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [NotificationCenter removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}

//鍵盤出現(xiàn)
- (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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末阻逮,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子颜价,更是在濱河造成了極大的恐慌,老刑警劉巖仪召,帶你破解...
    沈念sama閱讀 219,589評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件靶草,死亡現(xiàn)場離奇詭異,居然都是意外死亡幕垦,警方通過查閱死者的電腦和手機丢氢,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,615評論 3 396
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來先改,“玉大人疚察,你說我怎么就攤上這事〕鹉蹋” “怎么了貌嫡?”我有些...
    開封第一講書人閱讀 165,933評論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長该溯。 經(jīng)常有香客問我岛抄,道長,這世上最難降的妖魔是什么狈茉? 我笑而不...
    開封第一講書人閱讀 58,976評論 1 295
  • 正文 為了忘掉前任夫椭,我火速辦了婚禮,結(jié)果婚禮上氯庆,老公的妹妹穿的比我還像新娘蹭秋。我一直安慰自己,他們只是感情好堤撵,可當(dāng)我...
    茶點故事閱讀 67,999評論 6 393
  • 文/花漫 我一把揭開白布仁讨。 她就那樣靜靜地躺著,像睡著了一般粒督。 火紅的嫁衣襯著肌膚如雪陪竿。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,775評論 1 307
  • 那天屠橄,我揣著相機與錄音族跛,去河邊找鬼。 笑死锐墙,一個胖子當(dāng)著我的面吹牛礁哄,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播溪北,決...
    沈念sama閱讀 40,474評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼桐绒,長吁一口氣:“原來是場噩夢啊……” “哼夺脾!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起茉继,我...
    開封第一講書人閱讀 39,359評論 0 276
  • 序言:老撾萬榮一對情侶失蹤咧叭,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后烁竭,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體菲茬,經(jīng)...
    沈念sama閱讀 45,854評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,007評論 3 338
  • 正文 我和宋清朗相戀三年派撕,在試婚紗的時候發(fā)現(xiàn)自己被綠了婉弹。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,146評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡终吼,死狀恐怖镀赌,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情际跪,我是刑警寧澤商佛,帶...
    沈念sama閱讀 35,826評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站垫卤,受9級特大地震影響威彰,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜穴肘,卻給世界環(huán)境...
    茶點故事閱讀 41,484評論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望舔痕。 院中可真熱鬧评抚,春花似錦、人聲如沸伯复。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,029評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽啸如。三九已至侍匙,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間叮雳,已是汗流浹背想暗。 一陣腳步聲響...
    開封第一講書人閱讀 33,153評論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留帘不,地道東北人说莫。 一個月前我還...
    沈念sama閱讀 48,420評論 3 373
  • 正文 我出身青樓,卻偏偏與公主長得像寞焙,于是被迫代替她去往敵國和親储狭。 傳聞我的和親對象是個殘疾皇子互婿,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,107評論 2 356

推薦閱讀更多精彩內(nèi)容