MORemindAlertView.m 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. //
  2. // MORemindAlertView.m
  3. // MiMoLive
  4. //
  5. // Created by MiMo on 2025/8/21.
  6. //
  7. #import "MORemindAlertView.h"
  8. @interface MORemindAlertView ()
  9. @property (nonatomic, strong) UIView *backgroundView;
  10. @property (nonatomic, strong) UIView *contentView;
  11. @property (nonatomic, strong) UILabel *titleLabel;
  12. @property (nonatomic, strong) UIButton *remindButton;
  13. @property (nonatomic, strong) UIButton *leftButton;
  14. @property (nonatomic, strong) UIButton *rightButton;
  15. @end
  16. @implementation MORemindAlertView
  17. - (instancetype)init {
  18. if (self = [super init]) {
  19. [self setupUI];
  20. }
  21. return self;
  22. }
  23. - (void)setupUI {
  24. [self addSubview:self.backgroundView];
  25. [self.backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
  26. make.edges.mas_equalTo(0);
  27. }];
  28. [self addSubview:self.contentView];
  29. [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.center.mas_equalTo(0);
  31. make.width.mas_equalTo(kScaleWidth(295));
  32. make.height.mas_equalTo(158);
  33. }];
  34. [self.contentView addSubview:self.titleLabel];
  35. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.top.mas_equalTo(12);
  37. make.left.mas_equalTo(10);
  38. make.right.mas_equalTo(-10);
  39. }];
  40. [self.contentView addSubview:self.remindButton];
  41. [self.remindButton mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.bottom.mas_equalTo(-84);
  43. make.left.mas_equalTo(10);
  44. make.right.mas_equalTo(-10);
  45. }];
  46. [self.contentView addSubview:self.leftButton];
  47. [self.leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.bottom.mas_equalTo(-24);
  49. make.left.mas_equalTo(20);
  50. make.width.mas_equalTo(kScaleWidth(113));
  51. make.height.mas_equalTo(36);
  52. }];
  53. [self.contentView addSubview:self.rightButton];
  54. [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.bottom.mas_equalTo(-24);
  56. make.left.equalTo(self.leftButton.mas_right).offset(15);
  57. make.right.mas_equalTo(-20);
  58. make.height.mas_equalTo(36);
  59. }];
  60. }
  61. - (void)updateContentViewHeight {
  62. CGFloat otherHeight = 132;
  63. if (self.remindButton.isHidden) {
  64. otherHeight = 110;
  65. }
  66. CGFloat titleHeight = [MOTools getSizeFrom:self.titleLabel.text font:self.titleLabel.font maxSize:CGSizeMake(kScaleWidth(295) - 20, MAXFLOAT)].height;
  67. [self.contentView mas_updateConstraints:^(MASConstraintMaker *make) {
  68. make.height.mas_equalTo(titleHeight + otherHeight);
  69. }];
  70. }
  71. - (void)show {
  72. UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window;
  73. [self showInView:keyWindow];
  74. }
  75. - (void)showInView:(UIView *)superView {
  76. [superView addSubview:self];
  77. [self mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.edges.mas_equalTo(0);
  79. }];
  80. [self updateContentViewHeight];
  81. [self setNeedsLayout];
  82. [self layoutIfNeeded];
  83. self.contentView.transform = CGAffineTransformMakeScale(1.2, 1.2);
  84. self.contentView.alpha = 0;
  85. [UIView animateWithDuration:0.2 animations:^ {
  86. self.contentView.transform = CGAffineTransformMakeScale(1.0, 1.0);
  87. self.contentView.alpha = 1;
  88. }];
  89. }
  90. - (void)dismiss {
  91. [UIView animateWithDuration:0.2 animations:^ {
  92. self.contentView.transform = CGAffineTransformMakeScale(1.2, 1.2);
  93. self.contentView.alpha = 0;
  94. } completion:^(BOOL finished) {
  95. [self.contentView removeFromSuperview];
  96. [self removeFromSuperview];
  97. }];
  98. }
  99. - (void)setTitleText:(NSString *)titleText {
  100. _titleText = titleText;
  101. self.titleLabel.text = titleText;
  102. }
  103. - (void)setRemindText:(NSString *)remindText {
  104. _remindText = remindText;
  105. [self.remindButton setTitle:remindText forState:UIControlStateNormal];
  106. }
  107. - (void)setLeftButtonTitle:(NSString *)leftButtonTitle {
  108. _leftButtonTitle = leftButtonTitle;
  109. [self.leftButton setTitle:leftButtonTitle forState:UIControlStateNormal];
  110. }
  111. - (void)setRightButtonTitle:(NSString *)rightButtonTitle {
  112. _rightButtonTitle = rightButtonTitle;
  113. [self.rightButton setTitle:rightButtonTitle forState:UIControlStateNormal];
  114. }
  115. - (void)leftButtonAction {
  116. if (self.leftButtonBlock) {
  117. self.leftButtonBlock(self.remindButton.isSelected);
  118. }
  119. [self dismiss];
  120. }
  121. - (void)rightButtonAction {
  122. if (self.rightButtonBlock) {
  123. self.rightButtonBlock(self.remindButton.isSelected);
  124. }
  125. [self dismiss];
  126. }
  127. - (void)remindButtonAction:(UIButton *)btn {
  128. btn.selected = !btn.isSelected;
  129. if (btn.isSelected) {
  130. // if (self.fastGive) {//快捷送礼
  131. // [[MODataCache sharedYYCache] setObject:[NSDate date] forKey:kShowFastGiveConfirmViewKey];
  132. // } else {//跟送
  133. // [[MODataCache sharedYYCache] setObject:[NSDate date] forKey:kShowFollowGiveConfirmViewKey];
  134. // }
  135. } else {
  136. // if (self.fastGive) {//快捷送礼
  137. // [[MODataCache sharedYYCache] removeObjectForKey:kShowFastGiveConfirmViewKey];
  138. // } else {//跟送
  139. // [[MODataCache sharedYYCache] removeObjectForKey:kShowFollowGiveConfirmViewKey];
  140. // }
  141. }
  142. }
  143. - (void)hideRemindButton {
  144. self.remindButton.hidden = YES;
  145. [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  146. make.top.mas_equalTo(20);
  147. }];
  148. }
  149. #pragma mark - Lazy
  150. - (UIView *)backgroundView {
  151. if (!_backgroundView) {
  152. _backgroundView = [[UIView alloc] init];
  153. _backgroundView.backgroundColor = [MOTools colorWithHexString:@"#000000" alpha:0.6];
  154. // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)];
  155. // [_backgroundView addGestureRecognizer:tap];
  156. }
  157. return _backgroundView;
  158. }
  159. - (UIView *)contentView {
  160. if (!_contentView) {
  161. _contentView = [[UIView alloc] init];
  162. _contentView.layer.masksToBounds = YES;
  163. _contentView.layer.cornerRadius = 16;
  164. _contentView.backgroundColor = [MOTools colorWithHexString:@"#FFFFFF"];
  165. }
  166. return _contentView;
  167. }
  168. - (UILabel *)titleLabel {
  169. if (!_titleLabel) {
  170. _titleLabel = [[UILabel alloc] init];
  171. _titleLabel.font = [MOTextTools mediumFont:16];
  172. _titleLabel.textColor = kBaseTextColor_1;
  173. _titleLabel.text = NSLocalString(@"C20014");
  174. _titleLabel.textAlignment = NSTextAlignmentCenter;
  175. _titleLabel.numberOfLines = 0;
  176. }
  177. return _titleLabel;
  178. }
  179. - (UIButton *)remindButton {
  180. if (!_remindButton) {
  181. _remindButton = [[UIButton alloc] init];
  182. [_remindButton setImage:[UIImage imageNamed:@"icon_circle_blue_normal"] forState:UIControlStateNormal];
  183. [_remindButton setImage:[UIImage imageNamed:@"icon_circle_blue_selected"] forState:UIControlStateSelected];
  184. [_remindButton setTitle:NSLocalString(@"mimo_2_dont_remind") forState:UIControlStateNormal];
  185. _remindButton.titleLabel.font = [MOTextTools regularFont:14];
  186. [_remindButton setTitleColor:[MOTools colorWithHexString:@"#878A99"] forState:UIControlStateNormal];
  187. [_remindButton addTarget:self action:@selector(remindButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  188. }
  189. return _remindButton;
  190. }
  191. - (UIButton *)leftButton {
  192. if (!_leftButton) {
  193. _leftButton = [[UIButton alloc] init];
  194. [_leftButton setTitle:NSLocalString(@"C20015") forState:UIControlStateNormal];
  195. _leftButton.titleLabel.font = [MOTextTools regularFont:16];
  196. [_leftButton setTitleColor:kBaseTextColor_1 forState:UIControlStateNormal];
  197. _leftButton.layer.cornerRadius = 12;
  198. _leftButton.layer.masksToBounds = YES;
  199. _leftButton.layer.borderColor = [MOTools colorWithHexString:@"#DADCE6"].CGColor;
  200. _leftButton.layer.borderWidth = 1;
  201. [_leftButton addTarget:self action:@selector(leftButtonAction) forControlEvents:UIControlEventTouchUpInside];
  202. }
  203. return _leftButton;
  204. }
  205. - (UIButton *)rightButton {
  206. if (!_rightButton) {
  207. _rightButton = [[UIButton alloc] init];
  208. [_rightButton setTitle:NSLocalString(@"C20016") forState:UIControlStateNormal];
  209. [_rightButton setTitleColor:[MOTools colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
  210. _rightButton.titleLabel.font = [MOTextTools regularFont:16];
  211. NSArray *colorArr = @[kBaseColorLeft,kBaseColorRight];
  212. UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, kScaleWidth(255), 44) Colors:colorArr GradientType:0];
  213. [_rightButton setBackgroundImage:image forState:UIControlStateNormal];
  214. _rightButton.layer.cornerRadius = 12;
  215. _rightButton.layer.masksToBounds = YES;
  216. [_rightButton addTarget:self action:@selector(rightButtonAction) forControlEvents:UIControlEventTouchUpInside];
  217. }
  218. return _rightButton;
  219. }
  220. @end