CNWitnessShadeManager.m
3.68 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
106
107
108
109
//
// CNWitnessShadeManager.m
// CNLiveNetAdd
//
// Created by cnliveJunBo on 2019/7/5.
// Copyright © 2019年 cnlive. All rights reserved.
//
#import "CNWitnessShadeManager.h"
static CNWitnessShadeManager * instance = nil;
typedef void(^CancelBlock)(void);
@interface CNWitnessShadeManager ()
@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UIImageView *mjzView;
@property (nonatomic, strong) UIImageView *arrowsView;
@property (nonatomic, strong) UIImageView *titleView;
@property (nonatomic, strong) UIButton *cancelBtn;
@property (nonatomic, copy) NSString *topImgName;
@property (nonatomic, copy) NSString *contentImgName;
@property (nonatomic, assign) CGRect topImgRect;
@property (nonatomic, assign) CGSize contentImgSize;
@property (nonatomic, copy) CancelBlock cancelBlock;
@end
@implementation CNWitnessShadeManager
+ (void)showWitnessShadeViewWithTopImg:(NSString *)topImg contentImg:(NSString *)contentImg topImgRect:(CGRect)topImgRect contentImgSize:(CGSize)contentImgSize vc:(UIViewController *)vc cancelBlock:(void(^)(void))cancelBlock {
instance = [[self alloc] init];
instance.topImgName = topImg;
instance.contentImgName = contentImg;
instance.topImgRect = topImgRect;
instance.contentImgSize = contentImgSize;
instance.cancelBlock = cancelBlock;
[vc.view addSubview:instance.bgView];
[instance.bgView addSubview:instance.mjzView];
[instance.bgView addSubview:instance.arrowsView];
[instance.bgView addSubview:instance.titleView];
[instance.bgView addSubview:instance.cancelBtn];
if (instance.titleView.bottom>instance.cancelBtn.top-20) {
instance.cancelBtn.top=instance.titleView.bottom+20;
}
}
- (void)cancelAction:(UIButton *)sender {
[instance.mjzView removeFromSuperview];
[instance.arrowsView removeFromSuperview];
[instance.titleView removeFromSuperview];
[instance.cancelBtn removeFromSuperview];
instance.mjzView = nil;
instance.arrowsView = nil;
instance.titleView = nil;
instance.cancelBtn = nil;
[instance.bgView removeFromSuperview];
instance.bgView = nil;
if (instance.cancelBlock) {
instance.cancelBlock();
}
}
- (UIView *)bgView {
if (!_bgView) {
_bgView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
_bgView.backgroundColor = RGBA(0, 0, 0, 0.7);
}
return _bgView;
}
- (UIImageView *)mjzView {
if (!_mjzView) {
_mjzView = [[UIImageView alloc] initWithFrame:instance.topImgRect];
_mjzView.image = [UIImage loadBundleImage:instance.topImgName];
}
return _mjzView;
}
- (UIImageView *)arrowsView {
if (!_arrowsView) {
_arrowsView = [[UIImageView alloc] initWithFrame:CGRectMake(instance.mjzView.x+53, instance.mjzView.bottom+3, 47, 136)];
_arrowsView.image = [UIImage loadBundleImage:@"mjz-arrow"];
}
return _arrowsView;
}
- (UIImageView *)titleView {
if (!_titleView) {
_titleView = [[UIImageView alloc] initWithFrame:CGRectMake((KScreenWidth-instance.contentImgSize.width)*0.5, instance.arrowsView.bottom+10, instance.contentImgSize.width, instance.contentImgSize.height)];
_titleView.image = [UIImage loadBundleImage:instance.contentImgName];
}
return _titleView;
}
- (UIButton *)cancelBtn {
if (!_cancelBtn) {
_cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_cancelBtn.frame = CGRectMake((KScreenWidth-96)*0.5, 410.0*KScreenHeight/667.0, 96, 39);
[_cancelBtn setImage:[UIImage loadBundleImage:@"mjzgx_an"] forState:UIControlStateNormal];
[_cancelBtn addTarget:self action:@selector(cancelAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _cancelBtn;
}
@end