CNWitnessShadeManager.m 3.68 KB
//
//  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