BaseViewController.m 7.39 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

@property (nonatomic,strong) MBProgressHUD*TCHud;
勾芒's avatar
勾芒 committed
14
@property (nonatomic,strong) UIWebView *webView;
曹云霄's avatar
曹云霄 committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

@end

@implementation BaseViewController


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

勾芒's avatar
勾芒 committed
35 36 37 38 39 40 41 42 43 44 45

- (UIWebView *)webView
{
    if (_webView == nil) {
        
        _webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    }
    return _webView;
}


曹云霄's avatar
曹云霄 committed
46 47 48
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
勾芒's avatar
勾芒 committed
49 50
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = [UIColor whiteColor];
曹云霄's avatar
曹云霄 committed
51 52 53 54 55 56 57 58 59 60
}

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

#pragma mark -渐隐提示框回调
- (void)SHOWPrompttext:(NSString *)Text ComcpleteBlock:(void(^)())completed
{
61
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view.window animated:YES];
曹云霄's avatar
曹云霄 committed
62 63 64 65 66 67 68 69 70 71 72 73 74
    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等待视图
75
- (void)CreateMBProgressHUDLoding
曹云霄's avatar
曹云霄 committed
76 77 78
{
    self.TCHud.animationType = MBProgressHUDAnimationZoom;
    self.TCHud.mode = MBProgressHUDModeIndeterminate;
曹云霄's avatar
曹云霄 committed
79 80
    self.TCHud.color = [UIColor clearColor];
    self.TCHud.activityIndicatorColor = kMainBlueColor;
曹云霄's avatar
曹云霄 committed
81 82 83 84
    self.TCHud.removeFromSuperViewOnHide = YES;
}

#pragma mark -移除MBProgressHUD等待视图
85
- (void)RemoveMBProgressHUDLoding;
曹云霄's avatar
曹云霄 committed
86 87 88 89 90
{
    [self.TCHud hide:YES afterDelay:1];
    self.TCHud = nil;
}

91 92 93 94

#pragma mark -显示成功的提示框
- (void)SuccessMBProgressView:(NSString *)successString
{
95
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view.window animated:YES];
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
    // 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
{
113
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view.window animated:YES];
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    // 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
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143

#pragma mark -渐隐提示框
- (void)SHOWPrompttext:(NSString *)Text
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.labelText = Text;
    hud.margin = 10.f;
    hud.animationType = MBProgressHUDAnimationZoom;
    hud.mode = MBProgressHUDModeText;
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:1.0f];
    
}


曹云霄's avatar
曹云霄 committed
144 145 146 147 148 149 150 151 152 153 154 155 156
#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
157 158 159 160 161 162 163 164
#pragma mark -获得我的storyboard对象
- (UIStoryboard *)getStoryboardWithName
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"StoryboardwithCYX" bundle:nil];
    return storyboard;
}

#pragma mark 调用airPrint无线打印机
勾芒's avatar
勾芒 committed
165
- (void)callAirprintWithdata:(NSString *)PDFpath SuccessBlock:(void(^)())success ErrorBlock:(void(^)())failed
曹云霄's avatar
曹云霄 committed
166 167
{
    
勾芒's avatar
勾芒 committed
168
    NSData *mypdfdata = [NSData dataWithContentsOfFile:PDFpath];
曹云霄's avatar
曹云霄 committed
169 170 171 172 173 174 175 176 177 178 179
    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;
        
勾芒's avatar
勾芒 committed
180 181 182 183 184 185 186 187 188 189 190
        void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
            if (completed)
            {
                // 执行成功后的处理
                success();
            }
            else if (!completed && error)
            {
                // 执行失败后的处理
                failed();
            }
曹云霄's avatar
曹云霄 committed
191
        };
勾芒's avatar
勾芒 committed
192 193
        
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
曹云霄's avatar
曹云霄 committed
194 195 196 197 198 199
            
            [pic presentAnimated:YES completionHandler:completionHandler];
        }
    }
}

曹云霄's avatar
曹云霄 committed
200

勾芒's avatar
勾芒 committed
201 202 203 204



#pragma mark 调用airPrint无线打印机
勾芒's avatar
勾芒 committed
205
- (void)callAirprintWithURL:(NSURL *)datasurl SuccessBlock:(void (^)())success ErrorBlock:(void (^)())failed
勾芒's avatar
勾芒 committed
206 207 208 209 210 211 212 213 214 215 216 217
{
//    NSData *mypdfdata = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"The Swift Programming Language 中文版 - v1.2" ofType:@"pdf"]];
    
    UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];

        pic.delegate = self;
        [self.webView loadRequest:[NSURLRequest requestWithURL:datasurl]];//网页
        pic.printFormatter = [self.webView viewPrintFormatter];//布局打印视图绘制的内容。
        
        UIPrintInfo *printInfo = [UIPrintInfo printInfo];
        printInfo.outputType = UIPrintInfoOutputGeneral;
        printInfo.jobName = @"订单明细";
勾芒's avatar
勾芒 committed
218
        printInfo.duplex = UIPrintInfoDuplexShortEdge;
勾芒's avatar
勾芒 committed
219 220 221
        pic.printInfo = printInfo;
        pic.showsPageRange = YES;
    
勾芒's avatar
勾芒 committed
222 223 224 225 226 227 228 229 230 231
    void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
        if (completed)
        {
            // 执行成功后的处理
            success();
        }
        else if (!completed && error)
        {
            // 执行失败后的处理
            failed();
勾芒's avatar
勾芒 committed
232
        }
勾芒's avatar
勾芒 committed
233 234 235 236 237 238
    };

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        
        [pic presentAnimated:YES completionHandler:completionHandler];
    }
勾芒's avatar
勾芒 committed
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
}


















曹云霄's avatar
曹云霄 committed
258
@end