-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathNemoAlertBaseView.m
More file actions
105 lines (84 loc) · 2.97 KB
/
NemoAlertBaseView.m
File metadata and controls
105 lines (84 loc) · 2.97 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
102
103
104
105
//
// AlertBaseView.m
// TaiheXiudong
//
// Created by Nemo on 14-7-15.
// Copyright (c) 2014年 Jie Wang. All rights reserved.
//
#import "NemoAlertBaseView.h"
@interface NemoAlertBaseView ()
@end
@implementation NemoAlertBaseView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
CGRect frame = [UIApplication sharedApplication].keyWindow.bounds;
[self setFrame:frame];
_backView = [[UIView alloc]initWithFrame:frame];
_backView.alpha = 0.0;
_backView.backgroundColor = [UIColor blackColor];
[self addSubview:_backView];
UITapGestureRecognizer *dismiss = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hide:)];
[_backView addGestureRecognizer:dismiss];
}
return self;
}
+ (id)creatAlertView
{
return [[self alloc]initWithFrame:CGRectZero];
}
- (void)show:(BOOL)animation
{
[self show:animation completion:^(BOOL finished) {
}];
}
- (void)show:(BOOL)animation completion:(void (^)(BOOL finished))completion{
dispatch_async(dispatch_get_main_queue(), ^{
CGRect rect = self.bounds;
rect.origin.y = CGRectGetHeight(self.bounds);
self.backView.frame = rect;
CGRect frame = [UIApplication sharedApplication].keyWindow.bounds;
self.alertWindow = [[UIWindow alloc]initWithFrame:frame];
self.alertWindow.windowLevel = UIWindowLevelAlert;
self.alertWindow.backgroundColor = [UIColor clearColor];
[self.alertWindow makeKeyAndVisible];
[self.alertWindow addSubview:self];
if (animation) {
[UIView animateWithDuration:0.4 animations:^{
self.backView.frame = self.bounds;
self.backView.alpha = 0.7;
} completion:^(BOOL finished) {
completion(finished);
}];
}else{
self.backView.frame = self.bounds;
self.backView.alpha = 0.7;
}
});
}
- (void)hide:(BOOL)animation{
dispatch_async(dispatch_get_main_queue(), ^{
if (animation) {
[UIView animateWithDuration:0.4 animations:^{
CGRect rect = self.bounds;
rect.origin.y = CGRectGetHeight(self.bounds);
self.backView.frame = rect;
self.backView.alpha = 0.0;
} completion:^(BOOL finished) {
[[UIApplication sharedApplication].delegate.window makeKeyAndVisible];
self.alertWindow.hidden = YES;
self.alertWindow = nil;
}];
}else{
CGRect rect = self.bounds;
rect.origin.y = CGRectGetHeight(self.bounds);
self.backView.frame = rect;
self.backView.alpha = 0.0;
[[UIApplication sharedApplication].delegate.window makeKeyAndVisible];
self.alertWindow.hidden = YES;
self.alertWindow = nil;
}
});
}
@end