Browse Source

[*] 封装系统弹窗

Steven 6 months ago
parent
commit
babecac32f

+ 14 - 0
MiMoLive/MiMoLive.xcodeproj/project.pbxproj

@@ -76,6 +76,7 @@
 		3A8A05552E72D0A80081C87A /* MOPkRankSubView.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A8A054F2E72D0A80081C87A /* MOPkRankSubView.m */; };
 		3A8A056E2E73B7F80081C87A /* MONewAnchorRankEntryView.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A8A056D2E73B7F80081C87A /* MONewAnchorRankEntryView.m */; };
 		3A8A05872E745B920081C87A /* MORankNoDataView.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A8A05862E745B920081C87A /* MORankNoDataView.m */; };
+		3A8A063B2E7A96430081C87A /* MOSystemAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A8A063A2E7A96430081C87A /* MOSystemAlertView.m */; };
 		3A9160D42DD8DA380070C668 /* MORedPacketInfoView.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A9160D32DD8DA380070C668 /* MORedPacketInfoView.m */; };
 		3A9160D62DD9B8A40070C668 /* gif_diamond_drop.gif in Resources */ = {isa = PBXBuildFile; fileRef = 3A9160D52DD9B8A40070C668 /* gif_diamond_drop.gif */; };
 		3A9160D82DD9E41A0070C668 /* gif_send_red_packet.gif in Resources */ = {isa = PBXBuildFile; fileRef = 3A9160D72DD9E41A0070C668 /* gif_send_red_packet.gif */; };
@@ -1927,6 +1928,8 @@
 		3A8A056D2E73B7F80081C87A /* MONewAnchorRankEntryView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MONewAnchorRankEntryView.m; sourceTree = "<group>"; };
 		3A8A05852E745B920081C87A /* MORankNoDataView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MORankNoDataView.h; sourceTree = "<group>"; };
 		3A8A05862E745B920081C87A /* MORankNoDataView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MORankNoDataView.m; sourceTree = "<group>"; };
+		3A8A06392E7A96430081C87A /* MOSystemAlertView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MOSystemAlertView.h; sourceTree = "<group>"; };
+		3A8A063A2E7A96430081C87A /* MOSystemAlertView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MOSystemAlertView.m; sourceTree = "<group>"; };
 		3A9160D22DD8DA380070C668 /* MORedPacketInfoView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MORedPacketInfoView.h; sourceTree = "<group>"; };
 		3A9160D32DD8DA380070C668 /* MORedPacketInfoView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MORedPacketInfoView.m; sourceTree = "<group>"; };
 		3A9160D52DD9B8A40070C668 /* gif_diamond_drop.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = gif_diamond_drop.gif; sourceTree = "<group>"; };
@@ -5176,6 +5179,15 @@
 			path = NewPKRank;
 			sourceTree = "<group>";
 		};
+		3A8A06382E7A95710081C87A /* MOSystemAlertView */ = {
+			isa = PBXGroup;
+			children = (
+				3A8A06392E7A96430081C87A /* MOSystemAlertView.h */,
+				3A8A063A2E7A96430081C87A /* MOSystemAlertView.m */,
+			);
+			path = MOSystemAlertView;
+			sourceTree = "<group>";
+		};
 		3AA04C462DFAAD6C00127676 /* NewUser */ = {
 			isa = PBXGroup;
 			children = (
@@ -9554,6 +9566,7 @@
 		A6A63E8E2AF380AC009ED032 /* AlertView */ = {
 			isa = PBXGroup;
 			children = (
+				3A8A06382E7A95710081C87A /* MOSystemAlertView */,
 				A669B15D2C8EE2D00065EDD2 /* FirshRecharge */,
 				A6F3FBF22C33F64C00602D14 /* MODiamondWinAlertView */,
 				A6AD071B2C0F0CBE00A155CF /* MOGetGiftView */,
@@ -13186,6 +13199,7 @@
 				A61A8D222D22881A00D71489 /* QGHWDMetalRenderer.m in Sources */,
 				A6A08FB62B3933D900ECE79D /* MOMedalList.m in Sources */,
 				A6FC20F82B3D8C75001F4CC0 /* UIImageView+BarrageView.m in Sources */,
+				3A8A063B2E7A96430081C87A /* MOSystemAlertView.m in Sources */,
 				A6F0F5292CD8A46A0047B965 /* EaseMessageStatusView.m in Sources */,
 				3A1FDD9F2D58B2EB0042DDF2 /* UIImage+Extension.m in Sources */,
 				A6F0F5BE2CD8A46A0047B965 /* EaseTextFieldViewController.m in Sources */,

+ 33 - 0
MiMoLive/MiMoLive/Classes/Base/AlertView/MOSystemAlertView/MOSystemAlertView.h

@@ -0,0 +1,33 @@
+//
+//  MOSystemAlertView.h
+//  MiMoLive
+//
+//  Created by MiMo on 2025/9/17.
+//
+
+#import <UIKit/UIKit.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface MOSystemAlertView : UIView
+
+@property (nonatomic, copy) void (^confirmBlock) (void);
+
+@property (nonatomic, copy) void (^cancelBlock) (void);
+
+@property (nonatomic, copy) NSString *titleText;//标题
+@property (nonatomic, copy) NSString *contentText;//内容
+@property (nonatomic, copy) NSString *cancelButtonText;//取消文案(左边按钮)
+@property (nonatomic, copy) NSString *confirmButtonText;//确认文案(右边按钮)
+
+/** 是否单个按钮 */
+@property (nonatomic, assign) BOOL isSingleBtn;
+
+///view展示
+- (void)show;
+///view隐藏
+- (void)dismiss;
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 277 - 0
MiMoLive/MiMoLive/Classes/Base/AlertView/MOSystemAlertView/MOSystemAlertView.m

@@ -0,0 +1,277 @@
+//
+//  MOSystemAlertView.m
+//  MiMoLive
+//
+//  Created by MiMo on 2025/9/17.
+//
+
+#define kContentViewWidth kScaleWidth(295)
+
+#import "MOSystemAlertView.h"
+
+@interface MOSystemAlertView()
+
+@property (nonatomic, strong) UIView *bgView;
+@property (nonatomic, strong) UIView *contentView;
+@property (nonatomic, strong) UILabel *titleLabel;
+@property (nonatomic, strong) UILabel *contentLabel;
+@property (nonatomic, strong) UIView *hLineView;//横线
+@property (nonatomic, strong) UIView *vLineView;//竖线
+@property (nonatomic, strong) UIButton *cancelButton;
+@property (nonatomic, strong) UIButton *confirmButton;
+
+@end
+
+@implementation MOSystemAlertView
+
+- (instancetype)init {
+    if (self = [super init]) {
+        [self setupUI];
+    }
+    return self;
+}
+
+- (void)setupUI {
+    UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window;
+    [keyWindow addSubview:self.bgView];
+    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.top.left.bottom.right.equalTo(keyWindow);
+    }];
+    
+    [keyWindow addSubview:self.contentView];
+    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.width.mas_equalTo(kContentViewWidth);
+        make.center.mas_equalTo(0);
+        make.height.mas_equalTo(116);
+    }];
+    
+    [self.contentView addSubview:self.titleLabel];
+    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.top.mas_equalTo(24);
+        make.centerX.mas_equalTo(0);
+        make.left.mas_equalTo(20);
+        make.right.mas_equalTo(-20);
+    }];
+    
+    [self.contentView addSubview:self.contentLabel];
+    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.top.equalTo(self.titleLabel.mas_bottom).offset(8);//忽略行间距,暂时用8
+        make.centerX.mas_equalTo(0);
+        make.left.mas_equalTo(20);
+        make.right.mas_equalTo(-20);
+    }];
+    
+    [self.contentView addSubview:self.hLineView];
+    [self.hLineView mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.left.right.mas_equalTo(0);
+        make.bottom.mas_equalTo(-44);
+        make.height.mas_equalTo(1);
+    }];
+    
+    [self.contentView addSubview:self.vLineView];
+    [self.vLineView mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.centerX.mas_equalTo(0);
+        make.width.mas_equalTo(1);
+        make.top.equalTo(self.hLineView.mas_bottom);
+        make.bottom.mas_equalTo(0);
+    }];
+    
+    [self.contentView addSubview:self.cancelButton];
+    [self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.top.equalTo(self.hLineView.mas_bottom);
+        make.left.bottom.mas_equalTo(0);
+        make.width.equalTo(self.contentView.mas_width).multipliedBy(0.5);
+    }];
+    
+    [self.contentView addSubview:self.confirmButton];
+    [self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.top.equalTo(self.hLineView.mas_bottom);
+        make.right.bottom.mas_equalTo(0);
+        make.width.equalTo(self.contentView.mas_width).multipliedBy(0.5);
+    }];
+}
+
+- (void)cancelButtonAction {
+    if (self.cancelBlock) {
+        self.cancelBlock();
+    }
+    [self dismiss];
+}
+
+- (void)confirmButtonAction {
+    if (self.confirmBlock) {
+        self.confirmBlock();
+    }
+    [self dismiss];
+}
+
+- (void)setIsSingleBtn:(BOOL)isSingleBtn {
+    _isSingleBtn = isSingleBtn;
+    
+    if (isSingleBtn) {
+        self.cancelButton.hidden = YES;
+        self.vLineView.hidden = YES;
+
+        [self.confirmButton mas_remakeConstraints:^(MASConstraintMaker *make) {
+            make.top.equalTo(self.hLineView.mas_bottom);
+            make.right.bottom.mas_equalTo(0);
+            make.width.equalTo(self.contentView.mas_width).multipliedBy(1.0);
+        }];
+    }
+}
+
+- (void)setTitleText:(NSString *)titleText {
+    _titleText = titleText;
+    
+    self.titleLabel.text = titleText;
+}
+
+- (void)setContentText:(NSString *)contentText {
+    _contentText = contentText;
+    
+    self.contentLabel.text = contentText;
+}
+
+- (void)setCancelButtonText:(NSString *)cancelButtonText {
+    _cancelButtonText = cancelButtonText;
+    
+    [self.cancelButton setTitle:cancelButtonText forState:UIControlStateNormal];
+}
+
+- (void)setConfirmButtonText:(NSString *)confirmButtonText {
+    _confirmButtonText = confirmButtonText;
+    
+    [self.confirmButton setTitle:confirmButtonText forState:UIControlStateNormal];
+}
+
+- (void)calculateHeight{
+    //标题高度
+    CGFloat titleHeight = [MOTools calculateRowHeight:self.titleLabel.text font:self.titleLabel.font andWidth:kContentViewWidth - 40];
+    
+    CGFloat contentHeight = 0;
+    if (self.contentLabel.text.length > 0) {
+        contentHeight = [MOTools calculateRowHeight:self.contentLabel.text font:self.contentLabel.font andWidth:kContentViewWidth - 40];;
+    }
+    
+    //标题顶部距离
+    CGFloat titleTopSpacing = 24.0;
+    //内容占用距离
+    CGFloat contentLabelHeight = (contentHeight > 0) ? contentHeight + 5 : 0;//5是补偿行间距
+    //文字内容底部距离
+    CGFloat textBottomSpacing = 24.0;
+    //按钮高度
+    CGFloat buttonHeight = 44.0;
+    CGFloat contentViewHeight = titleTopSpacing + titleHeight + contentLabelHeight + textBottomSpacing + buttonHeight;
+    
+    [self.contentView mas_updateConstraints:^(MASConstraintMaker *make) {
+        make.height.mas_equalTo(contentViewHeight);
+    }];
+}
+
+- (void)show {
+    [self calculateHeight];
+    
+    UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window;
+    [keyWindow addSubview:self];
+    //动画效果
+    self.contentView.transform = CGAffineTransformMakeScale(1.2, 1.2);
+    self.contentView.alpha = 0;
+    [UIView animateWithDuration:0.2 animations:^ {
+        self.contentView.transform = CGAffineTransformMakeScale(1.0, 1.0);
+        self.contentView.alpha = 1;
+    } completion:nil];
+}
+
+- (void)dismiss {
+    [UIView animateWithDuration:0.2 animations:^ {
+        self.contentView.transform = CGAffineTransformMakeScale(1.2, 1.2);
+        self.contentView.alpha = 0;
+    } completion:^(BOOL finished) {
+        if (finished) {
+            [self.bgView removeFromSuperview];
+            [self.contentView removeFromSuperview];
+            [self removeFromSuperview];
+        }
+    }];
+}
+
+#pragma mark - Lazy
+- (UIView *)bgView {
+    if (!_bgView) {
+        _bgView = [[UIView alloc] init];
+        _bgView.backgroundColor = [MOTools colorWithHexString:@"#000000" alpha:0.4];
+        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)];
+        [_bgView addGestureRecognizer:tap];
+    }
+    return _bgView;
+}
+
+- (UIView *)contentView {
+    if (!_contentView) {
+        _contentView = [[UIView alloc] init];
+        _contentView.backgroundColor = [MOTools colorWithHexString:@"#FFFFFF"];
+        _contentView.layer.cornerRadius = 16;
+        _contentView.layer.masksToBounds = YES;
+    }
+    return _contentView;
+}
+
+- (UILabel *)titleLabel {
+    if (!_titleLabel) {
+        _titleLabel = [[UILabel alloc] init];
+        _titleLabel.font = [MOTextTools mediumFont:16];
+        _titleLabel.textColor = kBaseTextColor_1;
+        _titleLabel.textAlignment = NSTextAlignmentCenter;
+        _titleLabel.numberOfLines = 0;
+    }
+    return _titleLabel;
+}
+
+- (UILabel *)contentLabel {
+    if (!_contentLabel) {
+        _contentLabel = [[UILabel alloc] init];
+        _contentLabel.font = [MOTextTools regularFont:14];
+        _contentLabel.textColor = [MOTools colorWithHexString:@"#5C5E66"];
+        _contentLabel.textAlignment = NSTextAlignmentCenter;
+        _contentLabel.numberOfLines = 0;
+    }
+    return _contentLabel;
+}
+
+- (UIButton *)cancelButton {
+    if (!_cancelButton) {
+        _cancelButton = [[UIButton alloc] init];
+        _cancelButton.titleLabel.font = [MOTextTools regularFont:16];
+        [_cancelButton setTitleColor:[MOTools colorWithHexString:@"#5C5E66"] forState:UIControlStateNormal];
+        [_cancelButton addTarget:self action:@selector(cancelButtonAction) forControlEvents:UIControlEventTouchUpInside];
+    }
+    return _cancelButton;
+}
+
+- (UIButton *)confirmButton {
+    if (!_confirmButton) {
+        _confirmButton = [[UIButton alloc] init];
+        _confirmButton.titleLabel.font = [MOTextTools mediumFont:16];
+        [_confirmButton setTitleColor:[MOTools colorWithHexString:@"#4363FF"] forState:UIControlStateNormal];
+        [_confirmButton addTarget:self action:@selector(confirmButtonAction) forControlEvents:UIControlEventTouchUpInside];
+    }
+    return _confirmButton;
+}
+
+- (UIView *)hLineView {
+    if (!_hLineView) {
+        _hLineView = [[UIView alloc] init];
+        _hLineView.backgroundColor = [MOTools colorWithHexString:@"#DADCE6"];
+    }
+    return _hLineView;
+}
+
+- (UIView *)vLineView {
+    if (!_vLineView) {
+        _vLineView = [[UIView alloc] init];
+        _vLineView.backgroundColor = [MOTools colorWithHexString:@"#DADCE6"];
+    }
+    return _vLineView;
+}
+
+@end