MOVerificationView.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. //
  2. // MOVerificationView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2023/12/12.
  6. //
  7. #import "MOVerificationView.h"
  8. #import "MOSMSInputView.h"
  9. #import "NSString+YYAdd.h"
  10. #import "UIView+MOCornerRadius.h"
  11. @interface MOVerificationView ()
  12. @property (weak, nonatomic) IBOutlet UIView *bgView;
  13. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *bgViewHeight;
  14. @property (weak, nonatomic) IBOutlet UIImageView *headImg;
  15. @property (weak, nonatomic) IBOutlet UIButton *headBtn;
  16. @property (weak, nonatomic) IBOutlet UILabel *titleLab;
  17. @property (weak, nonatomic) IBOutlet UILabel *tipLab;
  18. @property (weak, nonatomic) IBOutlet UIView *ticketView;
  19. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *ticketViewHeight;
  20. @property (weak, nonatomic) IBOutlet UIButton *overBtn;
  21. @property (weak, nonatomic) IBOutlet UIButton *enterBtn;
  22. @property (weak, nonatomic) IBOutlet UIButton *ticketBtn;
  23. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *ticketBtnCenterX;
  24. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *ticketBtnWidth;
  25. @property (weak, nonatomic) IBOutlet UIImageView *ticketBgImgView;
  26. @property (weak, nonatomic) IBOutlet UILabel *ticketTipLab;
  27. @property (nonatomic, strong) MOSMSInputView *pswInputView;
  28. @property (nonatomic, copy) NSString *pswStr;
  29. @property (weak, nonatomic) IBOutlet UIButton *timeBtn;
  30. @property (weak, nonatomic) IBOutlet UILabel *offLab;
  31. @property (weak, nonatomic) IBOutlet UIImageView *offBgImg;
  32. @property (weak, nonatomic) IBOutlet UILabel *originalNumLab;
  33. @property (nonatomic, assign) BOOL isShow;
  34. @end
  35. @implementation MOVerificationView
  36. + (instancetype)moVerificationView{
  37. return [[[NSBundle mainBundle] loadNibNamed:@"MOVerificationView" owner:self options:nil] firstObject];
  38. }
  39. - (void)awakeFromNib{
  40. [super awakeFromNib];
  41. self.bgView.layer.cornerRadius = 17.0;
  42. self.headImg.layer.cornerRadius = 80.0 / 2.0;
  43. self.headImg.layer.borderWidth = 4.0;
  44. self.headImg.layer.borderColor = [UIColor whiteColor].CGColor;
  45. self.ticketView.layer.cornerRadius = 12.0;
  46. self.ticketView.layer.masksToBounds = YES;
  47. NSArray *ticketBgColorArr = @[[MOTools colorWithHexString:@"#FF4DA6" alpha:0.1],[MOTools colorWithHexString:@"#4363FF" alpha:0.1]];
  48. UIImage *ticketBgImage = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, 255.0, 134.0) Colors:ticketBgColorArr GradientType:0];
  49. [self.ticketBgImgView setImage:ticketBgImage];
  50. self.titleLab.font = [MOTextTools poppinsSemiBoldFont:16.0];
  51. self.tipLab.font = [MOTextTools lightFont:14.0];
  52. [self.overBtn setFont:[MOTextTools poppinsRegularFont:13.0]];
  53. NSArray *colorArr = @[kBaseColorLeft,kBaseColorRight];
  54. UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, (SCREENWIDTH - 20.0 * 2), 48.0) Colors:colorArr GradientType:0];
  55. [self.enterBtn setBackgroundImage:image forState:UIControlStateNormal];
  56. self.enterBtn.layer.cornerRadius = 12.0;
  57. self.enterBtn.layer.masksToBounds = YES;
  58. [self.enterBtn setFont:[MOTextTools poppinsMediumFont:16.0]];
  59. CGFloat width = 50.0 * 4.0 + 10.0 * 3.0 + 16.0 * 2.0;
  60. [self.bgView addSubview:self.pswInputView];
  61. [self.pswInputView mas_makeConstraints:^(MASConstraintMaker *make) {
  62. make.width.equalTo(@(width));
  63. make.height.equalTo(@50.0);
  64. make.top.equalTo(self.tipLab.mas_bottom).offset(20.0);
  65. make.centerX.equalTo(self.bgView.mas_centerX);
  66. }];
  67. self.offLab.layer.cornerRadius = 15.0 / 2.0;
  68. self.offLab.layer.masksToBounds = YES;
  69. self.tipLab.text = NSLocalString(@"mimo_room_auth_ticket_tip");
  70. self.ticketTipLab.text = [NSString stringWithFormat:NSLocalString(@"mimo_room_auth_ticket_tip"),20.0];
  71. MOMeDataInfo *userInfoData = (MOMeDataInfo *)[[MODataCache sharedYYCache] objectForKey:kMineUserInfo];
  72. [self.overBtn setTitle:[NSString stringWithFormat:@"%.f",userInfoData.userWallet.diamond] forState:UIControlStateNormal];
  73. [self.enterBtn setTitle:NSLocalString(@"mimo_room_auth_Unlock") forState:UIControlStateNormal];
  74. self.ticketBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 5);
  75. self.overBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 5);
  76. [self.timeBtn setFont:[MOTextTools poppinsRegularFont:10.0]];
  77. self.offLab.font = [MOTextTools mediumFont:9.0];
  78. [self.ticketBtn setFont:[MOTextTools poppinsSemiBoldFont:20.0]];
  79. self.originalNumLab.font = [MOTextTools poppinsRegularFont:16.0];
  80. self.ticketTipLab.font = [MOTextTools regularFont:12.0];
  81. NSArray *offColorArr = @[[MOTools colorWithHexString:@"#F18AFF" alpha:1.0],[MOTools colorWithHexString:@"#AE66FF" alpha:1.0]];
  82. UIImage *offImage = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, (SCREENWIDTH - 36.0 * 2), 50.0) Colors:offColorArr GradientType:0];
  83. [self.offBgImg setImage:offImage];
  84. [self.offBgImg setCornerRadiusWithTopLeft:8 topRight:8 bottomRight:8 bottomLeft:0];
  85. }
  86. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  87. {
  88. UITouch *touch = [touches anyObject];
  89. if ([touch.view isEqual:self.bgView] || [touch.view isEqual:self]){
  90. if(self.viewType == MOPswVerificationViewType){
  91. [self.pswInputView.textField resignFirstResponder];
  92. }
  93. }
  94. }
  95. - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
  96. {
  97. if (self.clipsToBounds || self.hidden || (self.alpha == 0.f))
  98. {
  99. return nil;
  100. }
  101. UIView *result = [super hitTest:point withEvent:event];
  102. // 把这个坐标从tabbar的坐标系转为subview的坐标系
  103. CGPoint subPoint = [self.headBtn convertPoint:point fromView:self];
  104. if([self.headBtn pointInside:subPoint withEvent:event]){
  105. return self.headBtn;
  106. }
  107. // 如果事件发生在tabbar里面直接返回
  108. return result;
  109. }
  110. - (IBAction)headBtnClick:(id)sender {
  111. NSString *userId = self.liveModel.currentRoom.anchorUser.id;
  112. if(userId.length > 0){
  113. self.headBtnBlock ? self.headBtnBlock(userId) : nil;
  114. }
  115. }
  116. - (IBAction)enterBtnClick:(id)sender {
  117. if(self.roomId.length == 0){
  118. return;
  119. }
  120. NSDictionary *dict;
  121. if(self.viewType == MOPswVerificationViewType){
  122. //密码验证
  123. if(self.pswStr.length == 0){
  124. [MBProgressHUD showTipMessageInWindow:NSLocalString(@"mimo_boot_tip_password")];
  125. return;
  126. }
  127. NSString *pswMd5 = [self.pswStr md5String];
  128. dict = @{@"id":self.roomId,
  129. @"password":pswMd5};
  130. }
  131. else{
  132. //门票付费
  133. dict = @{@"id":self.roomId};
  134. }
  135. [self toJoinCofirmWithDict:dict];
  136. }
  137. - (void)setLiveModel:(MOLiveDetail *)liveModel{
  138. _liveModel = liveModel;
  139. [self.headImg sd_setImageWithURL:[NSURL URLWithString:liveModel.currentRoom.anchorUser.avatar] placeholderImage:[UIImage imageNamed:@"icon_mine_placeHolder"]];
  140. self.titleLab.text = liveModel.currentRoom.name;
  141. if(liveModel.joinStatus == 2){
  142. self.tipLab.text = NSLocalString(@"mimo_room_auth_ticket_tip");
  143. if(liveModel.discount){
  144. self.timeBtn.hidden = NO;
  145. self.offLab.hidden = NO;
  146. self.offBgImg.hidden = NO;
  147. self.originalNumLab.hidden = NO;
  148. NSTimeInterval currentTime = [[NSDate date] timeIntervalSince1970] * 1000;
  149. NSTimeInterval time = round((liveModel.discountPeriod - currentTime) / 1000);
  150. NSString *timeStr = [NSDate formattedTimeStringFromTimeInterval:time AndFormatStr:@"HH:mm:ss"];
  151. [self.timeBtn setTitle:timeStr forState:UIControlStateNormal];
  152. self.offLab.text = [NSString stringWithFormat:@"%.f%% off",liveModel.discountRate];
  153. self.originalNumLab.text = [NSString stringWithFormat:@"%.f",liveModel.costDiamond];
  154. [self addObliqueStrikethroughToLabel:self.originalNumLab];
  155. self.ticketTipLab.text = [NSString stringWithFormat:NSLocalString(@"mimo_room_auth_ticket_discount_tip"),liveModel.discountRate];
  156. }
  157. else{
  158. self.timeBtn.hidden = YES;
  159. self.offLab.hidden = YES;
  160. self.offBgImg.hidden = YES;
  161. self.originalNumLab.hidden = YES;
  162. }
  163. [self.ticketBtn setTitle:[NSString stringWithFormat:@"%.f",liveModel.diamond] forState:UIControlStateNormal];
  164. [self.enterBtn setTitle:NSLocalString(@"mimo_room_auth_Unlock") forState:UIControlStateNormal];
  165. CGFloat ticketBtnWidth = [MOTools getWidthWithString:[NSString stringWithFormat:@"%.f",liveModel.diamond] font:[MOTextTools poppinsSemiBoldFont:20.0]] + 36.0;
  166. self.ticketBtnWidth.constant = ticketBtnWidth;
  167. }
  168. else{
  169. self.tipLab.text = NSLocalString(@"mimo_room_auth_password_tip");
  170. [self.enterBtn setTitle:NSLocalString(@"mimo_room_auth_Unlock") forState:UIControlStateNormal];
  171. }
  172. [self updataTheBgViewHeight];
  173. }
  174. - (void)updataTheBgViewHeight{
  175. CGFloat titleWidth = SCREENWIDTH - 30.0 * 2.0 - 15.0 * 2.0;
  176. CGFloat contentTipWidth = SCREENWIDTH - 30.0 * 4.0;
  177. CGFloat titleHeight = [MOTools calculateRowHeight:self.liveModel.currentRoom.name font:[MOTextTools poppinsSemiBoldFont:16.0] andWidth:titleWidth];
  178. if(titleHeight > 44.0){
  179. titleHeight = 44.0;
  180. }
  181. CGFloat contentTipHeight = [MOTools calculateRowHeight:self.tipLab.text font:[MOTextTools lightFont:14.0] andWidth:titleWidth];
  182. CGFloat customHeight = 0.0;
  183. if(self.liveModel.joinStatus == 2){
  184. //门票
  185. customHeight = 134.0;
  186. if(self.liveModel.discount){
  187. //有折扣
  188. CGFloat offTipWidth = SCREENWIDTH - 30.0 * 2.0 - 20.0 * 2.0;
  189. CGFloat offTipHeight = [MOTools calculateRowHeight:self.tipLab.text font:[MOTextTools regularFont:12.0] andWidth:offTipWidth];
  190. customHeight = 30.0 + 24.0 + offTipHeight + 50.0;
  191. self.ticketViewHeight.constant = customHeight;
  192. self.ticketBtnCenterX.constant = -20.0;
  193. }
  194. else{
  195. //无折扣
  196. CGFloat offTipWidth = SCREENWIDTH - 30.0 * 2.0 - 20.0 * 2.0;
  197. CGFloat offTipHeight = [MOTools calculateRowHeight:self.tipLab.text font:[MOTextTools regularFont:12.0] andWidth:offTipWidth];
  198. customHeight = 30.0 + 24.0 + offTipHeight + 20.0;
  199. self.ticketViewHeight.constant = customHeight;
  200. self.ticketBtnCenterX.constant = 0.0;
  201. }
  202. }
  203. else{
  204. customHeight = 50.0;
  205. }
  206. CGFloat viewHeight = 80.0 - 16.0 + 10.0 + titleHeight + 8.0 + contentTipHeight + 16.0 + customHeight + 24.0 + 44.0 + 52.0;
  207. self.bgViewHeight.constant = viewHeight;
  208. }
  209. //增加斜删除线
  210. - (void)addObliqueStrikethroughToLabel:(UILabel *)label {
  211. // 创建可变属性字符串
  212. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:label.text];
  213. // 添加斜的删除线
  214. [attributedString addAttribute:NSStrikethroughStyleAttributeName
  215. value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle)
  216. range:NSMakeRange(0, [label.text length])];
  217. // 添加斜线的角度
  218. [attributedString addAttribute:NSBaselineOffsetAttributeName
  219. value:@(0) // 调整这个值以改变斜线的倾斜程度
  220. range:NSMakeRange(0, [label.text length])];
  221. // 将带有斜的删除线的属性字符串设置为UILabel的属性字符串
  222. [label setAttributedText:attributedString];
  223. }
  224. - (void)toJoinCofirmWithDict:(NSDictionary *)dict{
  225. WEAKSELF
  226. [kHttpManager toJoinLiveWithConfirmWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  227. if(kCode_Success){
  228. MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  229. [weakSelf dismissVerificationView];
  230. MOLiveDetail *baseModel = [MOLiveDetail modelObjectWithDictionary:data[@"data"]];
  231. weakSelf.verificationSuccessBlock ? weakSelf.verificationSuccessBlock(baseModel) : nil;
  232. MOMeDataInfo *userInfoData = (MOMeDataInfo *)[[MODataCache sharedYYCache] objectForKey:kMineUserInfo];
  233. userInfoData.userWallet.diamond = baseModel.currentUserDiamond;
  234. [[MODataCache sharedYYCache] setObject:userInfoData forKey:kMineUserInfo];
  235. }
  236. else{
  237. kShowNetError(data)
  238. }
  239. }];
  240. }
  241. - (void)setBgViewBottom:(CGFloat)bgViewBottom{
  242. _bgViewBottom = bgViewBottom;
  243. // self.frame = CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT);
  244. //
  245. // WEAKSELF
  246. // [UIView animateWithDuration:0.3 animations:^{
  247. // CGRect actionViewRect = weakSelf.frame;
  248. // actionViewRect.origin.y = - bgViewBottom;
  249. // weakSelf.frame = actionViewRect;
  250. // }];
  251. }
  252. - (void)setViewType:(MOVerificationViewType)viewType{
  253. _viewType = viewType;
  254. if(viewType == MOTicketVerificationViewType){
  255. //门票
  256. self.ticketView.hidden = NO;
  257. self.pswInputView.hidden = YES;
  258. }
  259. else{
  260. //密码
  261. self.ticketView.hidden = YES;
  262. self.pswInputView.hidden = NO;
  263. }
  264. }
  265. - (IBAction)closeBtnClick:(id)sender {
  266. [self dismissVerificationView];
  267. }
  268. - (IBAction)liveTheRoomBtnClick:(id)sender {
  269. self.liveRoomBlock ? self.liveRoomBlock() : nil;
  270. [self dismissVerificationView];
  271. }
  272. - (void)showVerificationView{
  273. CGFloat viewHeight = SCREENHEIGHT - 100.0;
  274. self.frame = CGRectMake(0, 0, SCREENWIDTH, viewHeight);
  275. CGRect actionViewRect = self.bgView.frame;
  276. actionViewRect.origin.y = SCREENHEIGHT;
  277. self.bgView.frame = actionViewRect;
  278. WEAKSELF
  279. [UIView animateWithDuration:0.3 animations:^{
  280. CGRect actionViewRect = weakSelf.bgView.frame;
  281. actionViewRect.origin.y = SCREENHEIGHT - 383;
  282. weakSelf.bgView.frame = actionViewRect;
  283. }];
  284. // if(self.viewType == MOPswVerificationViewType){
  285. // [self.pswInputView.textField becomeFirstResponder];
  286. // }
  287. self.isShow = YES;
  288. }
  289. - (void)dismissVerificationView{
  290. //完成下移动画
  291. WEAKSELF
  292. [UIView animateWithDuration:0.3 animations:^
  293. {
  294. CGRect actionSheetViewRect = weakSelf.bgView.frame;
  295. actionSheetViewRect.origin.y = SCREENHEIGHT;
  296. weakSelf.bgView.frame = actionSheetViewRect;
  297. } completion:^(BOOL finished)
  298. {
  299. [self removeFromSuperview];
  300. }];
  301. self.isShow = NO;
  302. self.dismissViewBlock ? self.dismissViewBlock() : nil;
  303. }
  304. - (void)addOneSecond{
  305. if(self){
  306. if(self.isShow){
  307. if(self.viewType == MOTicketVerificationViewType && self.liveModel.joinStatus == 2){
  308. NSTimeInterval currentTime = [[NSDate date] timeIntervalSince1970] * 1000;
  309. NSTimeInterval time = round((self.liveModel.discountPeriod - currentTime) / 1000);
  310. NSString *timeStr = [NSDate formattedTimeStringFromTimeInterval:time AndFormatStr:@"HH:mm:ss"];
  311. [self.timeBtn setTitle:timeStr forState:UIControlStateNormal];
  312. }
  313. }
  314. }
  315. }
  316. #pragma mark - Lazy
  317. - (MOSMSInputView *)pswInputView
  318. {
  319. if (!_pswInputView)
  320. {
  321. WEAKSELF
  322. CGFloat width = 50.0;
  323. CGFloat height = 50.0;
  324. _pswInputView = [[MOSMSInputView alloc] initWithFrame:CGRectMake(0.0, 0.0, (width * 4.0 + 10.0 * 3.0 + 16.0 * 2.0), height) AndBoxSize:CGSizeMake(width, height) AndBoxNum:4.0 AndBoxSpace:10.0];
  325. _pswInputView.hidden = YES;
  326. _pswInputView.finishSMSCodeCallBack = ^(NSString * _Nonnull code)
  327. {
  328. weakSelf.pswStr = code;
  329. };
  330. _pswInputView.cleanCodeCallBack = ^(NSString * _Nonnull code) {
  331. weakSelf.pswStr = @"";
  332. };
  333. }
  334. return _pswInputView;
  335. }
  336. @end