// // QXExpansionCell.m // QXLive // // Created by 启星 on 2025/5/27. // #import "QXExpansionCell.h" #import "YBImageBrowser.h" #import "QXChatViewController.h" @interface QXExpansionCell() @property (nonatomic, strong) NSMutableArray *imgViewsArray; @end @implementation QXExpansionCell - (void)createUI { CGFloat imgWidth = (SCREEN_WIDTH-16*2-12*2-10*2)/3; for (NSInteger i = 0; i < 6; i++) { UIImageView *imgV = [[UIImageView alloc] init]; imgV.tag = i+100; imgV.userInteractionEnabled = YES; MJWeakSelf [imgV addTapBlock:^(id _Nonnull obj) { [weakSelf previewPhotoWithCurrentIndex:imgV.tag-100]; }]; imgV.hidden = YES; imgV.layer.masksToBounds = YES; imgV.layer.cornerRadius = 10; imgV.contentMode = UIViewContentModeScaleAspectFill; [self.imgsBgView addSubview:imgV]; [self.imgViewsArray addObject:imgV]; [imgV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.imgsBgView).offset((imgWidth+10)*(i/3)); make.left.equalTo(self.imgsBgView).offset((imgWidth+10)*(i%3)); make.size.mas_equalTo(CGSizeMake(imgWidth, imgWidth)); }]; } } - (IBAction)chatAction:(id)sender { if (self.model.room_id.intValue > 0) { // 去房间 [[QXGlobal shareGlobal] joinRoomWithRoomId:self.model.room_id isRejoin:NO navagationController:self.navigationController]; }else{ [[QXGlobal shareGlobal] chatWithUserID:self.model.user_id nickname:self.model.nickname avatar:self.model.avatar navagationController:self.navigationController]; } } -(void)setModel:(QXUserHomeModel *)model{ _model = model; [self.avatarImgV setHeadIcon:model.avatar dress:@""]; self.nicknameLab.text = model.nickname; self.ageLabel.text = [NSString stringWithFormat:@"%ld岁 ip属地: %@",[model.birthday ageWithDateOfBirth],model.loginip]; CGFloat imgWidth = (SCREEN_WIDTH-16*2-12*2-10*2)/3; UIImageView *firstImgV = self.imgViewsArray.firstObject; [firstImgV mas_updateConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(imgWidth, imgWidth)); }]; UIImage *sexImage = [UIImage imageNamed:model.sex.intValue==1?@"user_sex_boy":@"user_sex_girl"]; self.sexImageView.image = sexImage; NSArray *images; if (model.home_bgimages.length > 0) { images = [model.home_bgimages componentsSeparatedByString:@","]; } for (UIImageView *imgV in self.imgViewsArray) { imgV.hidden = YES; } for (NSInteger i = 0; i < images.count; i++) { if (i < self.imgViewsArray.count) { UIImageView *imgV = self.imgViewsArray[i]; imgV.hidden = NO; NSString *imageUrl = images[i]; [imgV sd_setImageWithURL:[NSURL URLWithString:imageUrl]]; } } self.imgsBgView.hidden = YES; if (images.count > 0) { if (images.count == 1) {//特殊 CGFloat itemW = (SCREEN_WIDTH-15-15-15)/2; CGFloat imgBgHeight = itemW; self.imgsBgView.hidden = NO; self.imgsBgViewHeightCon.constant = imgBgHeight; [firstImgV mas_updateConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(itemW, imgBgHeight)); }]; }else { CGFloat itemW = (SCREEN_WIDTH-16*2-12*2-10*2)/3; CGFloat imgBgHeight = 0; NSInteger lines = images.count%3 == 0 ? images.count/3 : images.count/3+1; imgBgHeight = itemW*lines + 10*(lines-1); self.imgsBgView.hidden = NO; if (images.count == 0) { self.imgsBgViewHeightCon.constant = 0; }else{ self.imgsBgViewHeightCon.constant = imgBgHeight; } } } if (self.model.room_id.intValue > 0) { self.followBtn.selected = YES; }else{ self.followBtn.selected = NO; } } -(void)previewPhotoWithCurrentIndex:(NSInteger)currentIndex{ NSArray *images = [self.model.home_bgimages componentsSeparatedByString:@","]; YBImageBrowser *browser = [YBImageBrowser new]; NSMutableArray *sourceArray = [NSMutableArray array]; for (int i = 0 ; i