基类控制器(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 
//如果有背景的话
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;
}


你可能感兴趣的:(工作总结)