| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439 |
- //
- // MOVerificationView.m
- // MiMoLive
- //
- // Created by SuperC on 2023/12/12.
- //
- #import "MOVerificationView.h"
- #import "MOSMSInputView.h"
- #import "NSString+YYAdd.h"
- #import "UIView+MOCornerRadius.h"
- @interface MOVerificationView ()
- @property (weak, nonatomic) IBOutlet UIView *bgView;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *bgViewHeight;
- @property (weak, nonatomic) IBOutlet UIImageView *headImg;
- @property (weak, nonatomic) IBOutlet UIButton *headBtn;
- @property (weak, nonatomic) IBOutlet UILabel *titleLab;
- @property (weak, nonatomic) IBOutlet UILabel *tipLab;
- @property (weak, nonatomic) IBOutlet UIView *ticketView;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *ticketViewHeight;
- @property (weak, nonatomic) IBOutlet UIButton *overBtn;
- @property (weak, nonatomic) IBOutlet UIButton *enterBtn;
- @property (weak, nonatomic) IBOutlet UIButton *ticketBtn;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *ticketBtnCenterX;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *ticketBtnWidth;
- @property (weak, nonatomic) IBOutlet UIImageView *ticketBgImgView;
- @property (weak, nonatomic) IBOutlet UILabel *ticketTipLab;
- @property (nonatomic, strong) MOSMSInputView *pswInputView;
- @property (nonatomic, copy) NSString *pswStr;
- @property (weak, nonatomic) IBOutlet UIButton *timeBtn;
- @property (weak, nonatomic) IBOutlet UILabel *offLab;
- @property (weak, nonatomic) IBOutlet UIImageView *offBgImg;
- @property (weak, nonatomic) IBOutlet UILabel *originalNumLab;
- @property (nonatomic, assign) BOOL isShow;
- @end
- @implementation MOVerificationView
- + (instancetype)moVerificationView{
- return [[[NSBundle mainBundle] loadNibNamed:@"MOVerificationView" owner:self options:nil] firstObject];
- }
- - (void)awakeFromNib{
- [super awakeFromNib];
-
- self.bgView.layer.cornerRadius = 17.0;
-
- self.headImg.layer.cornerRadius = 80.0 / 2.0;
- self.headImg.layer.borderWidth = 4.0;
- self.headImg.layer.borderColor = [UIColor whiteColor].CGColor;
-
- self.ticketView.layer.cornerRadius = 12.0;
- self.ticketView.layer.masksToBounds = YES;
-
- NSArray *ticketBgColorArr = @[[MOTools colorWithHexString:@"#FF4DA6" alpha:0.1],[MOTools colorWithHexString:@"#4363FF" alpha:0.1]];
- UIImage *ticketBgImage = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, 255.0, 134.0) Colors:ticketBgColorArr GradientType:0];
- [self.ticketBgImgView setImage:ticketBgImage];
-
- self.titleLab.font = [MOTextTools poppinsSemiBoldFont:16.0];
- self.tipLab.font = [MOTextTools lightFont:14.0];
- [self.overBtn setFont:[MOTextTools poppinsRegularFont:13.0]];
-
- NSArray *colorArr = @[kBaseColorLeft,kBaseColorRight];
- UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, (SCREENWIDTH - 20.0 * 2), 48.0) Colors:colorArr GradientType:0];
- [self.enterBtn setBackgroundImage:image forState:UIControlStateNormal];
- self.enterBtn.layer.cornerRadius = 12.0;
- self.enterBtn.layer.masksToBounds = YES;
- [self.enterBtn setFont:[MOTextTools poppinsMediumFont:16.0]];
-
- CGFloat width = 50.0 * 4.0 + 10.0 * 3.0 + 16.0 * 2.0;
- [self.bgView addSubview:self.pswInputView];
- [self.pswInputView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.equalTo(@(width));
- make.height.equalTo(@50.0);
- make.top.equalTo(self.tipLab.mas_bottom).offset(20.0);
- make.centerX.equalTo(self.bgView.mas_centerX);
- }];
-
- self.offLab.layer.cornerRadius = 15.0 / 2.0;
- self.offLab.layer.masksToBounds = YES;
-
- self.tipLab.text = NSLocalString(@"mimo_room_auth_ticket_tip");
- self.ticketTipLab.text = [NSString stringWithFormat:NSLocalString(@"mimo_room_auth_ticket_tip"),20.0];
-
- MOMeDataInfo *userInfoData = (MOMeDataInfo *)[[MODataCache sharedYYCache] objectForKey:kMineUserInfo];
- [self.overBtn setTitle:[NSString stringWithFormat:@"%.f",userInfoData.userWallet.diamond] forState:UIControlStateNormal];
-
- [self.enterBtn setTitle:NSLocalString(@"mimo_room_auth_Unlock") forState:UIControlStateNormal];
-
- self.ticketBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 5);
- self.overBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 5);
-
- [self.timeBtn setFont:[MOTextTools poppinsRegularFont:10.0]];
- self.offLab.font = [MOTextTools mediumFont:9.0];
- [self.ticketBtn setFont:[MOTextTools poppinsSemiBoldFont:20.0]];
- self.originalNumLab.font = [MOTextTools poppinsRegularFont:16.0];
- self.ticketTipLab.font = [MOTextTools regularFont:12.0];
-
- NSArray *offColorArr = @[[MOTools colorWithHexString:@"#F18AFF" alpha:1.0],[MOTools colorWithHexString:@"#AE66FF" alpha:1.0]];
- UIImage *offImage = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, (SCREENWIDTH - 36.0 * 2), 50.0) Colors:offColorArr GradientType:0];
- [self.offBgImg setImage:offImage];
- [self.offBgImg setCornerRadiusWithTopLeft:8 topRight:8 bottomRight:8 bottomLeft:0];
- }
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
- {
- UITouch *touch = [touches anyObject];
- if ([touch.view isEqual:self.bgView] || [touch.view isEqual:self]){
- if(self.viewType == MOPswVerificationViewType){
- [self.pswInputView.textField resignFirstResponder];
- }
- }
- }
- - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
- {
- if (self.clipsToBounds || self.hidden || (self.alpha == 0.f))
- {
- return nil;
- }
- UIView *result = [super hitTest:point withEvent:event];
-
- // 把这个坐标从tabbar的坐标系转为subview的坐标系
- CGPoint subPoint = [self.headBtn convertPoint:point fromView:self];
-
- if([self.headBtn pointInside:subPoint withEvent:event]){
- return self.headBtn;
- }
-
- // 如果事件发生在tabbar里面直接返回
- return result;
- }
- - (IBAction)headBtnClick:(id)sender {
- NSString *userId = self.liveModel.currentRoom.anchorUser.id;
-
- if(userId.length > 0){
- self.headBtnBlock ? self.headBtnBlock(userId) : nil;
- }
- }
- - (IBAction)enterBtnClick:(id)sender {
-
- if(self.roomId.length == 0){
- return;
- }
-
- NSDictionary *dict;
- if(self.viewType == MOPswVerificationViewType){
- //密码验证
- if(self.pswStr.length == 0){
- [MBProgressHUD showTipMessageInWindow:NSLocalString(@"mimo_boot_tip_password")];
- return;
- }
- NSString *pswMd5 = [self.pswStr md5String];
- dict = @{@"id":self.roomId,
- @"password":pswMd5};
- }
- else{
- //门票付费
- dict = @{@"id":self.roomId};
- }
-
- [self toJoinCofirmWithDict:dict];
- }
- - (void)setLiveModel:(MOLiveDetail *)liveModel{
- _liveModel = liveModel;
-
- [self.headImg sd_setImageWithURL:[NSURL URLWithString:liveModel.currentRoom.anchorUser.avatar] placeholderImage:[UIImage imageNamed:@"icon_mine_placeHolder"]];
- self.titleLab.text = liveModel.currentRoom.name;
-
- if(liveModel.joinStatus == 2){
-
- self.tipLab.text = NSLocalString(@"mimo_room_auth_ticket_tip");
-
- if(liveModel.discount){
- self.timeBtn.hidden = NO;
- self.offLab.hidden = NO;
- self.offBgImg.hidden = NO;
- self.originalNumLab.hidden = NO;
-
- NSTimeInterval currentTime = [[NSDate date] timeIntervalSince1970] * 1000;
-
- NSTimeInterval time = round((liveModel.discountPeriod - currentTime) / 1000);
- NSString *timeStr = [NSDate formattedTimeStringFromTimeInterval:time AndFormatStr:@"HH:mm:ss"];
- [self.timeBtn setTitle:timeStr forState:UIControlStateNormal];
-
- self.offLab.text = [NSString stringWithFormat:@"%.f%% off",liveModel.discountRate];
- self.originalNumLab.text = [NSString stringWithFormat:@"%.f",liveModel.costDiamond];
- [self addObliqueStrikethroughToLabel:self.originalNumLab];
-
-
- self.ticketTipLab.text = [NSString stringWithFormat:NSLocalString(@"mimo_room_auth_ticket_discount_tip"),liveModel.discountRate];
-
- }
- else{
- self.timeBtn.hidden = YES;
- self.offLab.hidden = YES;
- self.offBgImg.hidden = YES;
- self.originalNumLab.hidden = YES;
- }
-
- [self.ticketBtn setTitle:[NSString stringWithFormat:@"%.f",liveModel.diamond] forState:UIControlStateNormal];
- [self.enterBtn setTitle:NSLocalString(@"mimo_room_auth_Unlock") forState:UIControlStateNormal];
-
- CGFloat ticketBtnWidth = [MOTools getWidthWithString:[NSString stringWithFormat:@"%.f",liveModel.diamond] font:[MOTextTools poppinsSemiBoldFont:20.0]] + 36.0;
- self.ticketBtnWidth.constant = ticketBtnWidth;
- }
- else{
- self.tipLab.text = NSLocalString(@"mimo_room_auth_password_tip");
- [self.enterBtn setTitle:NSLocalString(@"mimo_room_auth_Unlock") forState:UIControlStateNormal];
- }
- [self updataTheBgViewHeight];
- }
- - (void)updataTheBgViewHeight{
- CGFloat titleWidth = SCREENWIDTH - 30.0 * 2.0 - 15.0 * 2.0;
- CGFloat contentTipWidth = SCREENWIDTH - 30.0 * 4.0;
- CGFloat titleHeight = [MOTools calculateRowHeight:self.liveModel.currentRoom.name font:[MOTextTools poppinsSemiBoldFont:16.0] andWidth:titleWidth];
- if(titleHeight > 44.0){
- titleHeight = 44.0;
- }
-
- CGFloat contentTipHeight = [MOTools calculateRowHeight:self.tipLab.text font:[MOTextTools lightFont:14.0] andWidth:titleWidth];
-
- CGFloat customHeight = 0.0;
- if(self.liveModel.joinStatus == 2){
- //门票
- customHeight = 134.0;
-
- if(self.liveModel.discount){
- //有折扣
- CGFloat offTipWidth = SCREENWIDTH - 30.0 * 2.0 - 20.0 * 2.0;
- CGFloat offTipHeight = [MOTools calculateRowHeight:self.tipLab.text font:[MOTextTools regularFont:12.0] andWidth:offTipWidth];
- customHeight = 30.0 + 24.0 + offTipHeight + 50.0;
- self.ticketViewHeight.constant = customHeight;
-
- self.ticketBtnCenterX.constant = -20.0;
- }
- else{
- //无折扣
- CGFloat offTipWidth = SCREENWIDTH - 30.0 * 2.0 - 20.0 * 2.0;
- CGFloat offTipHeight = [MOTools calculateRowHeight:self.tipLab.text font:[MOTextTools regularFont:12.0] andWidth:offTipWidth];
- customHeight = 30.0 + 24.0 + offTipHeight + 20.0;
- self.ticketViewHeight.constant = customHeight;
-
- self.ticketBtnCenterX.constant = 0.0;
- }
-
- }
- else{
- customHeight = 50.0;
- }
-
- CGFloat viewHeight = 80.0 - 16.0 + 10.0 + titleHeight + 8.0 + contentTipHeight + 16.0 + customHeight + 24.0 + 44.0 + 52.0;
-
- self.bgViewHeight.constant = viewHeight;
- }
- //增加斜删除线
- - (void)addObliqueStrikethroughToLabel:(UILabel *)label {
- // 创建可变属性字符串
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:label.text];
- // 添加斜的删除线
- [attributedString addAttribute:NSStrikethroughStyleAttributeName
- value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle)
- range:NSMakeRange(0, [label.text length])];
- // 添加斜线的角度
- [attributedString addAttribute:NSBaselineOffsetAttributeName
- value:@(0) // 调整这个值以改变斜线的倾斜程度
- range:NSMakeRange(0, [label.text length])];
- // 将带有斜的删除线的属性字符串设置为UILabel的属性字符串
- [label setAttributedText:attributedString];
- }
- - (void)toJoinCofirmWithDict:(NSDictionary *)dict{
- WEAKSELF
- [kHttpManager toJoinLiveWithConfirmWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- if(kCode_Success){
- MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
-
- [weakSelf dismissVerificationView];
- MOLiveDetail *baseModel = [MOLiveDetail modelObjectWithDictionary:data[@"data"]];
- weakSelf.verificationSuccessBlock ? weakSelf.verificationSuccessBlock(baseModel) : nil;
-
- MOMeDataInfo *userInfoData = (MOMeDataInfo *)[[MODataCache sharedYYCache] objectForKey:kMineUserInfo];
- userInfoData.userWallet.diamond = baseModel.currentUserDiamond;
- [[MODataCache sharedYYCache] setObject:userInfoData forKey:kMineUserInfo];
-
- }
- else{
- kShowNetError(data)
- }
- }];
- }
- - (void)setBgViewBottom:(CGFloat)bgViewBottom{
- _bgViewBottom = bgViewBottom;
-
- // self.frame = CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT);
- //
- // WEAKSELF
- // [UIView animateWithDuration:0.3 animations:^{
- // CGRect actionViewRect = weakSelf.frame;
- // actionViewRect.origin.y = - bgViewBottom;
- // weakSelf.frame = actionViewRect;
- // }];
- }
- - (void)setViewType:(MOVerificationViewType)viewType{
- _viewType = viewType;
-
- if(viewType == MOTicketVerificationViewType){
- //门票
- self.ticketView.hidden = NO;
- self.pswInputView.hidden = YES;
- }
- else{
- //密码
- self.ticketView.hidden = YES;
- self.pswInputView.hidden = NO;
- }
- }
- - (IBAction)closeBtnClick:(id)sender {
- [self dismissVerificationView];
- }
- - (IBAction)liveTheRoomBtnClick:(id)sender {
- self.liveRoomBlock ? self.liveRoomBlock() : nil;
- [self dismissVerificationView];
- }
- - (void)showVerificationView{
-
- CGFloat viewHeight = SCREENHEIGHT - 100.0;
-
- self.frame = CGRectMake(0, 0, SCREENWIDTH, viewHeight);
-
- CGRect actionViewRect = self.bgView.frame;
- actionViewRect.origin.y = SCREENHEIGHT;
- self.bgView.frame = actionViewRect;
-
- WEAKSELF
- [UIView animateWithDuration:0.3 animations:^{
- CGRect actionViewRect = weakSelf.bgView.frame;
- actionViewRect.origin.y = SCREENHEIGHT - 383;
- weakSelf.bgView.frame = actionViewRect;
- }];
-
- // if(self.viewType == MOPswVerificationViewType){
- // [self.pswInputView.textField becomeFirstResponder];
- // }
-
- self.isShow = YES;
- }
- - (void)dismissVerificationView{
- //完成下移动画
- WEAKSELF
- [UIView animateWithDuration:0.3 animations:^
- {
- CGRect actionSheetViewRect = weakSelf.bgView.frame;
- actionSheetViewRect.origin.y = SCREENHEIGHT;
- weakSelf.bgView.frame = actionSheetViewRect;
- } completion:^(BOOL finished)
- {
- [self removeFromSuperview];
- }];
-
- self.isShow = NO;
-
- self.dismissViewBlock ? self.dismissViewBlock() : nil;
- }
- - (void)addOneSecond{
- if(self){
- if(self.isShow){
- if(self.viewType == MOTicketVerificationViewType && self.liveModel.joinStatus == 2){
- NSTimeInterval currentTime = [[NSDate date] timeIntervalSince1970] * 1000;
- NSTimeInterval time = round((self.liveModel.discountPeriod - currentTime) / 1000);
- NSString *timeStr = [NSDate formattedTimeStringFromTimeInterval:time AndFormatStr:@"HH:mm:ss"];
- [self.timeBtn setTitle:timeStr forState:UIControlStateNormal];
- }
- }
- }
- }
- #pragma mark - Lazy
- - (MOSMSInputView *)pswInputView
- {
- if (!_pswInputView)
- {
- WEAKSELF
- CGFloat width = 50.0;
- CGFloat height = 50.0;
- _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];
- _pswInputView.hidden = YES;
- _pswInputView.finishSMSCodeCallBack = ^(NSString * _Nonnull code)
- {
- weakSelf.pswStr = code;
- };
- _pswInputView.cleanCodeCallBack = ^(NSString * _Nonnull code) {
- weakSelf.pswStr = @"";
- };
- }
- return _pswInputView;
- }
- @end
|