BaseViewController.m 5.26 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9 10
//
//  BaseViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/4/27.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "BaseViewController.h"

曹云霄's avatar
曹云霄 committed
11
@interface BaseViewController ()<UIPrintInteractionControllerDelegate>
曹云霄's avatar
曹云霄 committed
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

@property (nonatomic,strong) MBProgressHUD*TCHud;

@end

@implementation BaseViewController


/**
 *  创建MBProgressHUD对象
 *
 *  @return MBProgressHUD
 */
- (MBProgressHUD *)TCHud
{
    if (_TCHud == nil) {
        
        _TCHud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    }
    return _TCHud;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
37
    self.automaticallyAdjustsScrollViewInsets = NO; 
曹云霄's avatar
曹云霄 committed
38 39 40 41 42 43 44 45 46 47
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -渐隐提示框回调
- (void)SHOWPrompttext:(NSString *)Text ComcpleteBlock:(void(^)())completed
{
48
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
曹云霄's avatar
曹云霄 committed
49 50 51 52 53 54 55 56 57 58 59 60 61
    hud.labelText = Text;
    hud.animationType = MBProgressHUDAnimationZoom;
    hud.mode = MBProgressHUDModeText;
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:2.0f];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        if (completed) {
            completed();
        }
    });
}

#pragma mark -显示MBProgressHUD等待视图
62
- (void)CreateMBProgressHUDLoding
曹云霄's avatar
曹云霄 committed
63 64 65
{
    self.TCHud.animationType = MBProgressHUDAnimationZoom;
    self.TCHud.mode = MBProgressHUDModeIndeterminate;
曹云霄's avatar
曹云霄 committed
66 67
    self.TCHud.color = [UIColor clearColor];
    self.TCHud.activityIndicatorColor = kMainBlueColor;
曹云霄's avatar
曹云霄 committed
68 69 70 71
    self.TCHud.removeFromSuperViewOnHide = YES;
}

#pragma mark -移除MBProgressHUD等待视图
72
- (void)RemoveMBProgressHUDLoding;
曹云霄's avatar
曹云霄 committed
73 74 75 76 77
{
    [self.TCHud hide:YES afterDelay:1];
    self.TCHud = nil;
}

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

#pragma mark -显示成功的提示框
- (void)SuccessMBProgressView:(NSString *)successString
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    // Set the custom view mode to show any view.
    hud.mode = MBProgressHUDModeCustomView;
    // Set an image view with a checkmark.
    UIImage *image = [[UIImage imageNamed:@"Checkmark"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    hud.customView = [[UIImageView alloc] initWithImage:image];
    // Looks a bit nicer if we make it square.
    hud.square = YES;
    // Optional label text.
    hud.activityIndicatorColor = kMainBlueColor;
    hud.labelFont = [UIFont systemFontOfSize:12];
    hud.labelText = successString;
    [hud hide:YES afterDelay:1];
}

#pragma mark -显示错误的提示框
- (void)ErrorMBProgressView:(NSString *)errorString
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    // Set the custom view mode to show any view.
    hud.mode = MBProgressHUDModeCustomView;
    // Set an image view with a checkmark.
    UIImage *image = [[UIImage imageNamed:@"Error"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    hud.customView = [[UIImageView alloc] initWithImage:image];
    // Looks a bit nicer if we make it square.
    hud.square = YES;
    // Optional label text.
    hud.activityIndicatorColor = kMainBlueColor;
    hud.labelFont = [UIFont systemFontOfSize:12];
    hud.labelText = errorString;
    [hud hide:YES afterDelay:1];
}


曹云霄's avatar
曹云霄 committed
116 117 118 119 120 121 122 123 124 125 126 127 128
#pragma mark -结束MJRfresh刷新
- (void)endRefreshingForTableView:(UIScrollView *)TableView
{
    if (TableView.mj_header.isRefreshing) {
        
        [TableView.mj_header endRefreshing];
    }
    else if (TableView.mj_footer.isRefreshing)
    {
        [TableView.mj_footer endRefreshing];
    }
}

曹云霄's avatar
曹云霄 committed
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
#pragma mark -获得我的storyboard对象
- (UIStoryboard *)getStoryboardWithName
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"StoryboardwithCYX" bundle:nil];
    return storyboard;
}

#pragma mark 调用airPrint无线打印机
- (void)callAirprintWithdata:(NSData *)PDFdata
{
    NSData *mypdfdata = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"The Swift Programming Language 中文版 - v1.2" ofType:@"pdf"]];
    
    UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
    if  (pic && [UIPrintInteractionController canPrintData: mypdfdata] ) {
        pic.delegate = self;
        
        UIPrintInfo *printInfo = [UIPrintInfo printInfo];
        printInfo.outputType = UIPrintInfoOutputGeneral;
        printInfo.jobName = @"订单明细";
        printInfo.duplex = UIPrintInfoDuplexLongEdge;
        pic.printInfo = printInfo;
        pic.showsPageRange = YES;
        pic.printingItem = mypdfdata;
        
        void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
        ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
            if (!completed && error)
曹云霄's avatar
曹云霄 committed
156
                NSLog(@"FAILED! due to error in domain %@ with error code %ld",
曹云霄's avatar
曹云霄 committed
157 158 159 160 161 162 163 164 165 166 167
                      error.domain, error.code);
        };
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
            
            [pic presentAnimated:YES completionHandler:completionHandler];
        } else {
            [pic presentAnimated:YES completionHandler:completionHandler];
        }
    }
}

曹云霄's avatar
曹云霄 committed
168 169

@end