RescuePlanView.m 1.9 KB
//
//  RescuePlanView.m
//  DreamSleep
//
//  Created by peter on 2022/4/25.
//

#import "RescuePlanView.h"

@interface RescuePlanView ()
/// 拯救计划弹框图片
@property (nonatomic, strong) UIImageView *rescueIV;
/// 关闭按钮
@property (nonatomic, strong) UIButton *closeBtn;
@end

@implementation RescuePlanView

- (instancetype)initWithJumpBlock:(JumpBlock)block {
    if (self = [super initWithFrame:[UIScreen mainScreen].bounds]) {
        _block = block;
        self.backgroundColor = DarkColor;
        self.backgroundColor = [self.backgroundColor colorWithAlphaComponent:0.6];
        
        [self addSubview:self.rescueIV];
        [self addSubview:self.closeBtn];
        
        [self.rescueIV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self);
        }];
        [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.rescueIV);
            make.top.equalTo(self.rescueIV).offset(24);
        }];
    }
    return self;
}

#pragma mark - Actions
- (void)show {
    [DSKeyWindow addSubview:self];
}

- (void)dismiss {
    [self removeFromSuperview];
}

- (void)tapAction {
    [self dismiss];
    if (self.block) { self.block(); }
}

#pragma mark - lazy
- (UIImageView *)rescueIV {
    if (!_rescueIV) {
        _rescueIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pic_pop_normal"]];
        _rescueIV.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
        [_rescueIV addGestureRecognizer:tapGR];
    }
    return _rescueIV;
}

- (UIButton *)closeBtn {
    if (!_closeBtn) {
        _closeBtn = [UIButton new];
        [_closeBtn setImage:[UIImage imageNamed:@"home_close"] forState:UIControlStateNormal];
        [_closeBtn addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
    }
    return _closeBtn;
}

@end