基類控制器(BaseViewController)

        一個項目做了半年了,終於做完了,測試通過,提交審覈,這段時間無疑是最開心的日子,小酌一杯咖啡,聽段音樂,回過頭來看看這段時間的日子,苦中作樂.想想從iOS初級工程師,慢慢的蛻變到中級,中高級,是一個很不容易的過程,作爲一名中高級開發工程師,封裝一些公用的類,基類還是很有必要的,我想現在的我也可以去寫一些框架了,比如我們經常用到的基類控制器,其他的難題交給高級工程師去做吧,廢話少說,直接上代碼

#pragma mark - DataSource Change
//異步線程
- (void)exChangeMessageDataSourceQueue:(void (^)())queue {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
                   queue);
}
//回到主線程
- (void)exMainQueue:(void (^)())queue {
    dispatch_async(dispatch_get_main_queue(), queue);
}
//延時操作
- (void)exMainQueueTime:(NSInteger)time queue:(void (^)())queue {
    
    dispatch_after(
                   dispatch_time(DISPATCH_TIME_NOW, (int64_t)(time * NSEC_PER_SEC)),
                   dispatch_get_main_queue(), queue);
}
//====================================================
//
//  BaseViewController.h
//  ShowMe_iOS
//
//  Created by Fanjinxin on 15/11/26.
//  Copyright © 2015年 ShowMe. All rights reserved.
//

#import "PublicNavBar.h"
#import <UIKit/UIKit.h>
//如果有背景的話
typedef enum {
  BgImageTypeNavi,
  BgImageTypeNormal,
  BgImageTypeOther
} BgImageType;
@interface BaseViewController : UIViewController
/**
 *  加載StoryBoard
 */
+ (instancetype)loadStoryBoard;
/**
 *  跳轉(避免循環引用)
 */
- (void)weakPushVC:(UIViewController *)VC;
/**
 *  跳轉
 */
- (void)pushVC:(UIViewController *)VC;
- (void)weakPushVC:(UIViewController *)VC animated:(BOOL)animated;
- (void)pushVC:(UIViewController *)VC animated:(BOOL)animated;
- (void)weakToPopVC:(UIViewController *)VC;
- (void)popToVC:(UIViewController *)VC;
- (void)weakToPopVC:(UIViewController *)VC animated:(BOOL)animated;
- (void)popToVC:(UIViewController *)VC animated:(BOOL)animated;
/**
 * 導航欄
 */
@property(nonatomic, strong) PublicNavBar *navigationBar;

/**
 *  導航欄文字
 */
@property(nonatomic, copy) NSString *navTitle;

/**
 *  返回按鈕文字
 */
@property(nonatomic, copy) NSString *backButtonTitle;

/**
 *  導航欄背景圖片
 */
@property(nonatomic, copy) NSString *navBackGroundImage;

/**
 *  背景圖片
 */
@property(nonatomic, strong) UIImageView *backGroundImageView;
/**
 *  背景圖片類型 BgImageTypeNormal:PublicBgImage_1; BgImageTypeOther:...
 */
@property(nonatomic, assign) BgImageType bgImageType;
/**
 * 返回事件(當需點擊返回時調用,默認popView)
 */
- (void)back;
/**
 * 側滑事件(當需要右滑時調用,默認popView)
 */
- (void)handleSwipeGestureRecognizer:(UISwipeGestureRecognizer *)sgr;
/**
 * 是否允許導航控制器自帶的返回效果
 */
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer;
/**
 *  異步線程
 */
- (void)exChangeMessageDataSourceQueue:(void (^)())queue;
/**
 *  主線程
 */
- (void)exMainQueue:(void (^)())queue;
/**
 *  延時操作
 */
- (void)exMainQueueTime:(NSInteger)time queue:(void (^)())queue;
/**
 *  設置右側按鈕是否選中
 */
- (void)setRightBtnSelected:(BOOL)selected;

- (void)goLoginVC;
@end

加載storyBoard

+ (instancetype)loadStoryBoard {
    
    NSString *vcName = [NSString stringWithFormat:@"%@", [self class]];
    if ([vcName hasSuffix:@"ViewController"]) {
        vcName = [vcName stringByReplacingOccurrencesOfString:@"ViewController"
                                                   withString:@""];
    } else if ([vcName hasSuffix:@"Controller"]) {
        vcName = [vcName stringByReplacingOccurrencesOfString:@"Controller"
                                                   withString:@""];
    }
    return [UIStoryboard storyboardWithName:vcName bundle:nil]
    .instantiateInitialViewController;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章