Files
featherVoice/QXLive/Room(房间)/View/签约房/QXSignAlertView.m
2025-12-01 18:42:49 +08:00

131 lines
4.5 KiB
Objective-C

//
// QXSignAlertView.m
// QXLive
//
// Created by 启星 on 2025/12/1.
//
#import "QXSignAlertView.h"
@interface QXSignAlertView()
@property (nonatomic,strong)UIView *bgView;
@property (nonatomic,strong)UIImageView *imageView;
@property (nonatomic,strong)UIButton *closeBtn;
@property (assign,nonatomic)QXSignAlerType type;
@end
@implementation QXSignAlertView
-(instancetype)initWithType:(QXSignAlerType)type{
self = [super init];
if (self) {
_type = type;
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
[self initSubviewsWithType:type];
}
return self;
}
-(void)initSubviewsWithType:(QXSignAlerType)type{
self.bgView = [[UIView alloc] init];
[self addSubview:self.bgView];
switch (type) {
case QXSignAlerTypeStart:{
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(ScaleWidth(222));
make.height.mas_equalTo(ScaleWidth(222));
make.centerX.centerY.equalTo(self);
}];
self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"room_sign_start"]];
self.imageView.contentMode = UIViewContentModeScaleToFill;
[self.bgView addSubview:self.imageView];
[self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.bgView);
}];
}
break;
case QXSignAlerTypeFail:
{
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(ScaleWidth(272));
make.height.mas_equalTo(ScaleWidth(397));
make.centerX.centerY.equalTo(self);
}];
self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"room_sign_fail"]];
[self.bgView addSubview:self.imageView];
[self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.bgView);
}];
self.closeBtn = [[UIButton alloc] init];
[self.closeBtn setBackgroundImage:[UIImage imageNamed:@"room_sign_fail_btn"] forState:(UIControlStateNormal)];
[self.closeBtn addTarget:self action:@selector(hide) forControlEvents:(UIControlEventTouchUpInside)];
[self.bgView addSubview:self.closeBtn];
[self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(ScaleWidth(-29));
make.width.mas_equalTo(ScaleWidth(139));
make.height.mas_equalTo(ScaleWidth(51));
make.centerX.equalTo(self.bgView);
}];
}
break;
case QXSignAlerTypeSuccess:
{
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(ScaleWidth(222));
make.height.mas_equalTo(ScaleWidth(222));
make.centerX.centerY.equalTo(self);
}];
self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"room_sign_success"]];
[self.bgView addSubview:self.imageView];
[self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.bgView);
}];
}
break;
default:
break;
}
}
-(void)showInView:(UIView*)view{
[view addSubview:self];
self.bgView.alpha = 0;
[UIView animateWithDuration:0.3 animations:^{
self.bgView.alpha = 1;
}completion:^(BOOL finished) {
}];
[self performSelector:@selector(hide) afterDelay:1];
}
- (void)hide{
if (!self.superview) {
NSLog(@"⚠️ View already removed from superview");
return;
}
__weak typeof(self) weakSelf = self;
[UIView animateWithDuration:0.3 animations:^{
__strong typeof(weakSelf) strongSelf = weakSelf;
if (!strongSelf) {
NSLog(@"⚠️ self has been deallocated, skipping hide operation");
return;
}
self.bgView.alpha = 0;
}completion:^(BOOL finished) {
__strong typeof(weakSelf) strongSelf = weakSelf;
if (!strongSelf) {
NSLog(@"⚠️ self has been deallocated, skipping hide operation");
return;
}
if (self.superview) {
[self removeFromSuperview];
}
}];
}
@end