| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- //
- // MORemindAlertView.m
- // MiMoLive
- //
- // Created by MiMo on 2025/8/21.
- //
- #import "MORemindAlertView.h"
- @interface MORemindAlertView ()
- @property (nonatomic, strong) UIView *backgroundView;
- @property (nonatomic, strong) UIView *contentView;
- @property (nonatomic, strong) UILabel *titleLabel;
- @property (nonatomic, strong) UIButton *remindButton;
- @property (nonatomic, strong) UIButton *leftButton;
- @property (nonatomic, strong) UIButton *rightButton;
- @end
- @implementation MORemindAlertView
- - (instancetype)init {
- if (self = [super init]) {
- [self setupUI];
- }
- return self;
- }
- - (void)setupUI {
- [self addSubview:self.backgroundView];
- [self.backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(0);
- }];
-
- [self addSubview:self.contentView];
- [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.mas_equalTo(0);
- make.width.mas_equalTo(kScaleWidth(295));
- make.height.mas_equalTo(158);
- }];
-
- [self.contentView addSubview:self.titleLabel];
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(12);
- make.left.mas_equalTo(10);
- make.right.mas_equalTo(-10);
- }];
-
- [self.contentView addSubview:self.remindButton];
- [self.remindButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.mas_equalTo(-84);
- make.left.mas_equalTo(10);
- make.right.mas_equalTo(-10);
- }];
-
- [self.contentView addSubview:self.leftButton];
- [self.leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.mas_equalTo(-24);
- make.left.mas_equalTo(20);
- make.width.mas_equalTo(kScaleWidth(113));
- make.height.mas_equalTo(36);
- }];
-
- [self.contentView addSubview:self.rightButton];
- [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.mas_equalTo(-24);
- make.left.equalTo(self.leftButton.mas_right).offset(15);
- make.right.mas_equalTo(-20);
- make.height.mas_equalTo(36);
- }];
- }
- - (void)updateContentViewHeight {
-
- CGFloat otherHeight = 132;
- if (self.remindButton.isHidden) {
- otherHeight = 110;
- }
-
- CGFloat titleHeight = [MOTools getSizeFrom:self.titleLabel.text font:self.titleLabel.font maxSize:CGSizeMake(kScaleWidth(295) - 20, MAXFLOAT)].height;
- [self.contentView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(titleHeight + otherHeight);
- }];
- }
- - (void)show {
- UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window;
- [self showInView:keyWindow];
- }
- - (void)showInView:(UIView *)superView {
-
- [superView addSubview:self];
- [self mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(0);
- }];
-
- [self updateContentViewHeight];
-
- [self setNeedsLayout];
- [self layoutIfNeeded];
-
- 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;
- }];
- }
- - (void)dismiss {
- [UIView animateWithDuration:0.2 animations:^ {
- self.contentView.transform = CGAffineTransformMakeScale(1.2, 1.2);
- self.contentView.alpha = 0;
- } completion:^(BOOL finished) {
- [self.contentView removeFromSuperview];
- [self removeFromSuperview];
- }];
- }
- - (void)setTitleText:(NSString *)titleText {
- _titleText = titleText;
-
- self.titleLabel.text = titleText;
- }
- - (void)setRemindText:(NSString *)remindText {
- _remindText = remindText;
-
- [self.remindButton setTitle:remindText forState:UIControlStateNormal];
- }
- - (void)setLeftButtonTitle:(NSString *)leftButtonTitle {
- _leftButtonTitle = leftButtonTitle;
-
- [self.leftButton setTitle:leftButtonTitle forState:UIControlStateNormal];
- }
- - (void)setRightButtonTitle:(NSString *)rightButtonTitle {
- _rightButtonTitle = rightButtonTitle;
-
- [self.rightButton setTitle:rightButtonTitle forState:UIControlStateNormal];
- }
- - (void)leftButtonAction {
- if (self.leftButtonBlock) {
- self.leftButtonBlock(self.remindButton.isSelected);
- }
- [self dismiss];
- }
- - (void)rightButtonAction {
- if (self.rightButtonBlock) {
- self.rightButtonBlock(self.remindButton.isSelected);
- }
- [self dismiss];
- }
- - (void)remindButtonAction:(UIButton *)btn {
- btn.selected = !btn.isSelected;
-
- if (btn.isSelected) {
- // if (self.fastGive) {//快捷送礼
- // [[MODataCache sharedYYCache] setObject:[NSDate date] forKey:kShowFastGiveConfirmViewKey];
- // } else {//跟送
- // [[MODataCache sharedYYCache] setObject:[NSDate date] forKey:kShowFollowGiveConfirmViewKey];
- // }
- } else {
- // if (self.fastGive) {//快捷送礼
- // [[MODataCache sharedYYCache] removeObjectForKey:kShowFastGiveConfirmViewKey];
- // } else {//跟送
- // [[MODataCache sharedYYCache] removeObjectForKey:kShowFollowGiveConfirmViewKey];
- // }
- }
- }
- - (void)hideRemindButton {
- self.remindButton.hidden = YES;
- [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(20);
- }];
- }
- #pragma mark - Lazy
- - (UIView *)backgroundView {
- if (!_backgroundView) {
- _backgroundView = [[UIView alloc] init];
- _backgroundView.backgroundColor = [MOTools colorWithHexString:@"#000000" alpha:0.6];
- // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)];
- // [_backgroundView addGestureRecognizer:tap];
- }
- return _backgroundView;
- }
- - (UIView *)contentView {
- if (!_contentView) {
- _contentView = [[UIView alloc] init];
- _contentView.layer.masksToBounds = YES;
- _contentView.layer.cornerRadius = 16;
- _contentView.backgroundColor = [MOTools colorWithHexString:@"#FFFFFF"];
- }
- return _contentView;
- }
- - (UILabel *)titleLabel {
- if (!_titleLabel) {
- _titleLabel = [[UILabel alloc] init];
- _titleLabel.font = [MOTextTools mediumFont:16];
- _titleLabel.textColor = kBaseTextColor_1;
- _titleLabel.text = NSLocalString(@"C20014");
- _titleLabel.textAlignment = NSTextAlignmentCenter;
- _titleLabel.numberOfLines = 0;
- }
- return _titleLabel;
- }
- - (UIButton *)remindButton {
- if (!_remindButton) {
- _remindButton = [[UIButton alloc] init];
- [_remindButton setImage:[UIImage imageNamed:@"icon_circle_blue_normal"] forState:UIControlStateNormal];
- [_remindButton setImage:[UIImage imageNamed:@"icon_circle_blue_selected"] forState:UIControlStateSelected];
- [_remindButton setTitle:NSLocalString(@"mimo_2_dont_remind") forState:UIControlStateNormal];
- _remindButton.titleLabel.font = [MOTextTools regularFont:14];
- [_remindButton setTitleColor:[MOTools colorWithHexString:@"#878A99"] forState:UIControlStateNormal];
- [_remindButton addTarget:self action:@selector(remindButtonAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _remindButton;
- }
- - (UIButton *)leftButton {
- if (!_leftButton) {
- _leftButton = [[UIButton alloc] init];
- [_leftButton setTitle:NSLocalString(@"C20015") forState:UIControlStateNormal];
- _leftButton.titleLabel.font = [MOTextTools regularFont:16];
- [_leftButton setTitleColor:kBaseTextColor_1 forState:UIControlStateNormal];
- _leftButton.layer.cornerRadius = 12;
- _leftButton.layer.masksToBounds = YES;
- _leftButton.layer.borderColor = [MOTools colorWithHexString:@"#DADCE6"].CGColor;
- _leftButton.layer.borderWidth = 1;
- [_leftButton addTarget:self action:@selector(leftButtonAction) forControlEvents:UIControlEventTouchUpInside];
- }
- return _leftButton;
- }
- - (UIButton *)rightButton {
- if (!_rightButton) {
- _rightButton = [[UIButton alloc] init];
- [_rightButton setTitle:NSLocalString(@"C20016") forState:UIControlStateNormal];
- [_rightButton setTitleColor:[MOTools colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
- _rightButton.titleLabel.font = [MOTextTools regularFont:16];
- NSArray *colorArr = @[kBaseColorLeft,kBaseColorRight];
- UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, kScaleWidth(255), 44) Colors:colorArr GradientType:0];
- [_rightButton setBackgroundImage:image forState:UIControlStateNormal];
- _rightButton.layer.cornerRadius = 12;
- _rightButton.layer.masksToBounds = YES;
- [_rightButton addTarget:self action:@selector(rightButtonAction) forControlEvents:UIControlEventTouchUpInside];
- }
- return _rightButton;
- }
- @end
|