-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRFUILock.m
117 lines (95 loc) · 2.26 KB
/
RFUILock.m
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
106
107
108
109
110
111
112
113
114
115
116
117
//
// RFUILock.m
// KeDao
//
// Created by gouzhehua on 15-2-26.
// Copyright (c) 2015年 skyInfo. All rights reserved.
//
#import "RFUILock.h"
#import "RFColor.h"
#import "RFUIKit.h"
@interface RFUILockView ()
{
}
@end
@interface RFUILockWindow ()
@end
@implementation RFUILockView
+ (void)lockView:(UIView *)view transparent:(BOOL)isTransparent click:(void(^)(void))clickBlock
{
[RFUILockView unlockView:view];
RFUILockView *lockView = [[RFUILockView alloc] initWithFrame:view.bounds];
lockView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
lockView.clickBlock = clickBlock;
lockView.userInteractionEnabled = YES;
lockView.backgroundColor = RGBA2COLOR(0, 0, 0, 0);
[lockView setTapActionWithTarget:lockView selector:@selector(onLockViewClick:)];
[view addSubview:lockView];
if (!isTransparent)
{
[UIView animateWithDuration:0.2
animations:^(){
lockView.backgroundColor = RGBA2COLOR(0, 0, 0, 0.4);
}
completion:^(BOOL isFinish){
}];
}
}
+ (void)unlockView:(UIView *)view
{
for (UIView *lockView in view.subviews)
{
if ([lockView isKindOfClass:[RFUILockView class]])
{
[UIView animateWithDuration:0.2
animations:^(){
lockView.backgroundColor = RGBA2COLOR(0, 0, 0, 0.0);
}
completion:^(BOOL isFinish){
[lockView removeFromSuperview];
}];
}
}
}
- (void)onLockViewClick:(id)sender
{
if (self.clickBlock != nil)
{
self.clickBlock();
}
}
@end
@implementation RFUILockWindow
+ (RFUILockWindow *)shared
{
static RFUILockWindow *s_instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
s_instance = [[RFUILockWindow alloc] init];
});
return s_instance;
}
- (void)lockWithTransparent:(BOOL)isTransparent click:(void(^)(void))clickBlock
{
if (self.window != nil)
{
[self unlock];
}
self.window = [[RFUIWindow alloc] init];
self.window.backgroundColor = [UIColor clearColor];
if (isTransparent)
self.window.bgView.backgroundColor = RGBA2COLOR(0, 0, 0, 0);
else
self.window.bgView.backgroundColor = RGBA2COLOR(0, 0, 0, 0.6);
self.window.bgClickBlock = clickBlock;
[self.window show];
}
- (void)unlock
{
if (self.window != nil)
{
[self.window dismiss];
}
self.window = nil;
}
@end