MOTitleAndTefAlertView.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. //
  2. // MOTitleAndTefAlertView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2023/11/5.
  6. //
  7. #define LBINPUTALERTVIEWHEIGHT 380
  8. #import "MOTitleAndTefAlertView.h"
  9. #import "MOPlaceHolderTextView.h"
  10. @interface MOTitleAndTefAlertView ()<UITextViewDelegate>
  11. /** 背景 */
  12. @property (nonatomic, strong) UIView *bgView;
  13. /** 白色弹窗view */
  14. @property (nonatomic, strong) UIView *containerView;
  15. /** 背景图 */
  16. @property (nonatomic, strong) UIImageView *bgImgView;
  17. /** 标题 */
  18. @property (nonatomic, strong) UILabel *titleLabel;
  19. /** 确认 */
  20. @property (nonatomic, strong) BigBtn *confirmBtn;
  21. @property (nonatomic, strong) MOPlaceHolderTextView *textView;
  22. @property (nonatomic, strong) UILabel *tipLab;
  23. @end
  24. @implementation MOTitleAndTefAlertView
  25. - (instancetype)init
  26. {
  27. if (self = [super init])
  28. {
  29. [self setupUI];
  30. }
  31. return self;
  32. }
  33. - (void)setupUI{
  34. UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window;
  35. [keyWindow addSubview:self.bgView];
  36. [self.bgView mas_makeConstraints:^(MASConstraintMaker *make)
  37. {
  38. make.top.left.bottom.right.equalTo(keyWindow);
  39. }];
  40. [keyWindow addSubview:self.containerView];
  41. [self.containerView mas_makeConstraints:^(MASConstraintMaker *make)
  42. {
  43. make.width.mas_equalTo(SCREENWIDTH * 0.76);
  44. make.centerY.equalTo(keyWindow).with.offset(-100.0);
  45. make.centerX.equalTo(keyWindow);
  46. make.height.mas_equalTo(LBINPUTALERTVIEWHEIGHT);
  47. }];
  48. [self.containerView addSubview:self.bgImgView];
  49. [self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.edges.equalTo(self.containerView);
  51. }];
  52. //标题
  53. [self.containerView addSubview:self.titleLabel];
  54. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make)
  55. {
  56. make.left.equalTo(self.containerView).with.offset(16.0);
  57. make.right.equalTo(self.containerView).with.offset(-16.0);
  58. make.top.equalTo(self.containerView).with.offset(28);
  59. }];
  60. //确定Button
  61. [self.containerView addSubview:self.confirmBtn];
  62. [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make)
  63. {
  64. make.left.equalTo(self.containerView).offset(55.0);
  65. make.right.equalTo(self.containerView).offset(-55.0);
  66. make.bottom.equalTo(self.containerView).offset(-20.0);
  67. make.height.equalTo(@42.0);
  68. }];
  69. NSArray *colorArr = @[kBaseBtnBgColor,kBaseBtnBgColor];
  70. UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, (SCREENWIDTH * 0.76 - 55.0 * 2), 48.0) Colors:colorArr GradientType:0];
  71. [self.confirmBtn setBackgroundImage:image forState:UIControlStateNormal];
  72. //输入框
  73. [self.containerView addSubview:self.textView];
  74. [self.textView mas_makeConstraints:^(MASConstraintMaker *make)
  75. {
  76. make.left.equalTo(self.containerView).with.offset(16);
  77. make.right.equalTo(self.containerView).with.offset(-16);
  78. make.top.equalTo(self.titleLabel.mas_bottom).with.offset(20);
  79. make.bottom.equalTo(self.confirmBtn.mas_top).offset(-20.0);
  80. }];
  81. [self.containerView addSubview:self.tipLab];
  82. [self.tipLab mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.right.equalTo(self.textView.mas_right).offset(-10.0);
  84. make.bottom.equalTo(self.textView.mas_bottom).offset(-10.0);
  85. }];
  86. }
  87. - (void)textViewDidChange:(UITextView *)textView{
  88. [self checkStatus];
  89. }
  90. ///更新界面文字监听状态
  91. - (void)checkStatus
  92. {
  93. NSString *text = self.textView.text;
  94. NSInteger length = text.length;
  95. NSInteger leftLength = 200 - length;
  96. self.tipLab.text = [NSString stringWithFormat:@"%ld/200", (long)length];
  97. if (leftLength >= 0)
  98. {
  99. [self.tipLab setTextColor:[MOTools colorWithHexString:@"#DBAFDF" alpha:1.0]];
  100. }
  101. else
  102. {
  103. [self.tipLab setTextColor:[MOTools colorWithHexString:@"#CCCCCC" alpha:1.0]];
  104. }
  105. }
  106. - (void)calculateHeight{
  107. //主标题高度
  108. CGFloat titleHeight = [MOTools calculateRowHeight:self.titleLabel.text font:[UIFont boldSystemFontOfSize:19.0] andWidth:(SCREENWIDTH * 0.76 - 16.0 * 2)];
  109. CGFloat contentViewHeight = 20.0 + titleHeight + 20.0 + 180.0 + 20.0 + 48.0 + 20.0;
  110. [self.containerView mas_updateConstraints:^(MASConstraintMaker *make)
  111. {
  112. make.height.mas_equalTo(contentViewHeight);
  113. }];
  114. }
  115. - (void)show//界面显示动画
  116. {
  117. [self calculateHeight];
  118. UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window;
  119. [keyWindow addSubview:self];
  120. //动画效果
  121. self.containerView.transform = CGAffineTransformMakeScale(1.3, 1.3);
  122. self.containerView.alpha = 0;
  123. [UIView animateWithDuration:0.2 animations:^
  124. {
  125. self.containerView.transform = CGAffineTransformMakeScale(1.0, 1.0);
  126. self.containerView.alpha = 1;
  127. } completion:^(BOOL finished)
  128. {
  129. }];
  130. }
  131. - (void)confirmBtnClick//点击确认
  132. {
  133. if(self.textView.text.length > 200){
  134. [MBProgressHUD showTipMessageInWindow:NSLocalString(@"mimo_common_enter_limit")];
  135. }
  136. [self.textView resignFirstResponder];
  137. if (![self.textView.text isEmpty])//有输入才dismiss
  138. {
  139. [self dismiss];
  140. }
  141. if (self.confirmBlock)
  142. {
  143. self.confirmBlock(self.textView.text);
  144. }
  145. }
  146. - (void)dismiss//取消掉键盘
  147. {
  148. [self.textView resignFirstResponder];
  149. [UIView animateWithDuration:0.2 animations:^
  150. {
  151. self.containerView.transform = CGAffineTransformMakeScale(1.3, 1.3);
  152. self.containerView.alpha = 0;
  153. } completion:^(BOOL finished)
  154. {
  155. if (finished)
  156. {
  157. [self.bgView removeFromSuperview];
  158. [self.containerView removeFromSuperview];
  159. [self removeFromSuperview];
  160. }
  161. }];
  162. }
  163. #pragma mark - 懒加载
  164. - (UIView *)bgView
  165. {
  166. if (!_bgView)
  167. {
  168. _bgView = [[UIView alloc] init];
  169. _bgView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
  170. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)];
  171. [_bgView addGestureRecognizer:tap];
  172. }
  173. return _bgView;
  174. }
  175. - (UIView *)containerView
  176. {
  177. if (!_containerView)
  178. {
  179. _containerView = [[UIView alloc] init];
  180. _containerView.backgroundColor = [UIColor clearColor];
  181. _containerView.layer.masksToBounds = YES;
  182. _containerView.layer.cornerRadius = 12.0;
  183. }
  184. return _containerView;
  185. }
  186. - (UILabel *)titleLabel
  187. {
  188. if (!_titleLabel)
  189. {
  190. _titleLabel = [[UILabel alloc] init];
  191. _titleLabel.textColor = [MOTools colorWithHexString:@"#282828" alpha:1.0];;
  192. _titleLabel.font = [MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr];
  193. _titleLabel.textAlignment = NSTextAlignmentCenter;
  194. _titleLabel.numberOfLines = 0;
  195. _titleLabel.text = NSLocalString(@"mimo_family_apply_reason_title");
  196. }
  197. return _titleLabel;
  198. }
  199. - (BigBtn *)confirmBtn
  200. {
  201. if (!_confirmBtn)
  202. {
  203. _confirmBtn = [[BigBtn alloc] init];
  204. [_confirmBtn addTarget:self action:@selector(confirmBtnClick) forControlEvents:UIControlEventTouchUpInside];
  205. [_confirmBtn setTitle:NSLocalString(@"mimo_fans_fans_club_create_submit") forState:UIControlStateNormal];
  206. [_confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  207. _confirmBtn.layer.masksToBounds = YES;
  208. _confirmBtn.layer.cornerRadius = 42.0 / 2.0;
  209. [_confirmBtn setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]];
  210. }
  211. return _confirmBtn;
  212. }
  213. - (MOPlaceHolderTextView *)textView{
  214. if(!_textView){
  215. _textView = [[MOPlaceHolderTextView alloc] init];
  216. _textView.placeholder = NSLocalString(@"mimo_family_apply_reason_placeholder");
  217. _textView.backgroundColor = [MOTools colorWithHexString:@"#F1FDFF" alpha:1.0];
  218. _textView.font = [MOTextTools getTheFontWithSize:14.0 AndFontName:kNormalContentFontStr];
  219. _textView.textColor = [MOTools colorWithHexString:@"#282828" alpha:1.0];
  220. _textView.layer.cornerRadius = 12.0;
  221. _textView.layer.masksToBounds = YES;
  222. _textView.layer.borderColor = [MOTools colorWithHexString:@"#17CBEA" alpha:1.0].CGColor;
  223. _textView.layer.borderWidth = 0.5;
  224. _textView.delegate = self;
  225. }
  226. return _textView;
  227. }
  228. - (UILabel *)tipLab
  229. {
  230. if (!_tipLab)
  231. {
  232. _tipLab = [[UILabel alloc] init];
  233. _tipLab.textColor = [MOTools colorWithHexString:@"#ABABAB" alpha:1.0];;
  234. _tipLab.font = [MOTextTools getTheFontWithSize:14.0 AndFontName:kNormalContentFontStr];
  235. _tipLab.textAlignment = NSTextAlignmentRight;
  236. _tipLab.numberOfLines = 0;
  237. _tipLab.text = @"0/200";
  238. }
  239. return _tipLab;
  240. }
  241. - (UIImageView *)bgImgView{
  242. if(!_bgImgView){
  243. _bgImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_alert_bg"]];
  244. _bgImgView.contentMode = UIViewContentModeScaleToFill;
  245. _bgImgView.backgroundColor = [UIColor clearColor];
  246. }
  247. return _bgImgView;
  248. }
  249. @end