Hud.m
2.42 KB
1
2
3
4
5
6
7
8
9
10
11
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
// Hud.m
// Pantheon
//
// Created by 常 屹 on 14/6/11.
// Copyright (c) 2014年 常 屹. All rights reserved.
//
#import "Hud.h"
#import "MBProgressHUD.h"
#import "AppDelegate.h"
#define IPHONE5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
@implementation Hud
static Hud *instance = nil;
+ (instancetype)defaultInstance
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[Hud alloc] init];
});
return instance;
}
- (id)init
{
self = [super init];
if (self) {
UINavigationController *navController = (UINavigationController *)[UIApplication sharedApplication].delegate.window.rootViewController;
mbProgressHUD = [[MBProgressHUD alloc] initWithView:navController.view];
}
return self;
}
- (void)showMessage:(NSString *)message
{
[self showMessage:message withHud:NO];
}
- (void)showMessage:(NSString *)message withHud:(BOOL)flag
{
if (!flag) {
[[UIApplication sharedApplication].delegate.window addSubview:mbProgressHUD];
[mbProgressHUD show:YES];
}
mbProgressHUD.mode = MBProgressHUDModeText;
mbProgressHUD.labelText = @"";
mbProgressHUD.detailsLabelText = message;
mbProgressHUD.margin = 10.f;
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIsLandscape(orientation)) {
mbProgressHUD.yOffset = 80.f;
}
else {
if (IPHONE5) {
mbProgressHUD.yOffset = 200.f;
}
else {
mbProgressHUD.yOffset = 150.f;
}
}
mbProgressHUD.removeFromSuperViewOnHide = YES;
[mbProgressHUD hide:YES afterDelay:2.f];
}
- (void)loading:(UIView *)view
{
[self loading:view withText:@"加载中,请稍后..."];
}
- (void)loading:(UIView *)view withText:(NSString *)text
{
mbProgressHUD.margin = 20.f;
mbProgressHUD.labelText = text;
mbProgressHUD.detailsLabelText = @"";
mbProgressHUD.mode = MBProgressHUDModeIndeterminate;
mbProgressHUD.yOffset = 0.f;
[view addSubview:mbProgressHUD];
[mbProgressHUD show:YES];
}
- (void)hide:(UIView *)view
{
//[MBProgressHUD hideHUDForView:[AppDelegate appDelegate].window animated:YES];
[MBProgressHUD hideHUDForView:view animated:YES];
}
@end