// // THBottleInfoCardContentView.m // TreeHole // // Created by iOS on 2023/2/9. // Copyright © 2023 CYH. All rights reserved. // #import "THBottleInfoCardContentView.h" #import "THBottleInfoImagesCollectionCell.h" @interface THBottleInfoCardContentView () @property(nonatomic, strong)QMUILabel *textLb; @property(nonatomic, strong)UICollectionView *photosView; //语音 @property(nonatomic, strong)QMUIButton *voiceBarBtn; //管理员 ///被回应?次 @property(nonatomic, strong)UILabel *responseNumLb; @end @implementation THBottleInfoCardContentView //MARK: - Set - (void)setModel:(id)model { //判断类型?写真:交换照片 //多图:写真--> 是会员 ? 能滚动,图片清晰 : 不能滚动,图片模糊; //单图:交换照片,不能滚动---> 是否交换 ? 显示真图 : 显示占位 } - (void)setVoiceUrl:(NSString *)voiceUrl { _voiceUrl = voiceUrl; self.voiceBarBtn.hidden = voiceUrl.isEmpty; } - (void)setImgs:(NSArray *)imgs { _imgs = imgs; self.photosView.hidden = !imgs.count; [self.photosView reloadData]; } - (void)setContentText:(NSString *)contentText { _contentText = contentText; self.textLb.text = contentText; self.textLb.hidden = contentText.isEmpty; } - (void)setBottleType:(THBottleType)bottleType { _bottleType = bottleType; //UI显隐 // if (bottleType == THBottleType_Text) { // // return; // } if (bottleType == THBottleType_TextAndVoice || bottleType == THBottleType_Exchange_Voice) { //声音 self.voiceBarBtn.hidden = NO; self.photosView.hidden = YES; return; } if (bottleType == THBottleType_TextAndPicture || bottleType == THBottleType_Exchange_Picture) { //图片 self.voiceBarBtn.hidden = YES; self.photosView.hidden = NO; return; } //文本 self.voiceBarBtn.hidden = YES; self.photosView.hidden = YES; } //- (void)setImgIsSee:(BOOL)imgIsSee { // _imgIsSee = imgIsSee; // //} //MARK: - Setup - (void)setupSubViews { _textLb = [QMUILabel creatLabelWithFont:UIFontMediumMake(14) textColor:UIColorMakeWithHex(@"#FFFFFF") inSuperView:self]; _textLb.numberOfLines = 0; _textLb.qmui_lineHeight = [_textLb.font lineHeight]; _responseNumLb = [QMUILabel creatLabelWithFont:UIFontMediumMake(14) textColor:UIColorMakeWithHex(@"#FFFFFF") inSuperView:self]; _responseNumLb.text = @"被回应了?次"; // _responseNumLb.hidden = YES; _voiceBarBtn = [QMUIButton creatButtonWithFontSize:W_Scale(14) fontWeight:UIFontWeightMedium textColorHex:@"#FFB902" textState:UIControlStateNormal inSuperView:self]; _voiceBarBtn.backgroundColor = UIColorMakeWithHex(@"#FFB902"); _voiceBarBtn.cornerRadius = 4; [_voiceBarBtn setImage:UIImageMake(@"message_voice_sender_normal") forState:UIControlStateNormal]; [_voiceBarBtn setTitle:@"1'" forState:UIControlStateNormal]; _voiceBarBtn.hidden = YES; UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal; flowLayout.itemSize = CGSizeMake(80, 110); _photosView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout]; _photosView.backgroundColor = [UIColor clearColor]; _photosView.showsHorizontalScrollIndicator = NO; _photosView.bounces = NO; // _photosView.contentInset = UIEdgeInsetsMake(0, 22, 0, 22); _photosView.dataSource = self; _photosView.delegate = self; [self addSubview:_photosView]; [_photosView registerClass:THBottleInfoImagesCollectionCell.class forCellWithReuseIdentifier:NSStringFromClass(THBottleInfoImagesCollectionCell.class)]; // _textLb.text = NSStringFromClass(_textLb.class); } - (void)layoutSubviews { [super layoutSubviews]; CGSize textLbSize = [self.textLb sizeThatFits:self.bounds.size]; self.textLb.frame = CGRectMake(0, 0, textLbSize.width, textLbSize.height); if (THNetworkInterfaceService.isManager) { //管理员布局 [self.responseNumLb sizeToFit]; self.responseNumLb.qmui_width = self.qmui_width; self.responseNumLb.qmui_left = 0; self.responseNumLb.qmui_top = self.textLb.qmui_bottom; } if (!self.voiceBarBtn.isHidden) { CGFloat voiceBarBtnY = THNetworkInterfaceService.isManager ? (self.responseNumLb.qmui_bottom + 5) : (self.textLb.qmui_bottom + 10); self.voiceBarBtn.frame = CGRectMake(0, voiceBarBtnY, self.qmui_width * 0.7, 44); } if (!self.photosView.isHidden) { //单行展示 CGFloat singleRowH = self.qmui_height - self.textLb.qmui_bottom - 10; CGFloat photosViewY = THNetworkInterfaceService.isManager ? (self.responseNumLb.qmui_bottom + 5) : (self.textLb.qmui_bottom + 10); self.photosView.frame = CGRectMake(0, photosViewY, self.qmui_width, singleRowH); } } - (CGSize)sizeThatFits:(CGSize)size { //单行 CGSize textLbSize = [self.textLb sizeThatFits:CGSizeMake(self.qmui_width, CGFLOAT_MAX)]; return CGSizeMake(size.width, textLbSize.height + 10 + 100 + 10); } //MARK: - - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.imgs.count; } - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { THBottleInfoImagesCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass(THBottleInfoImagesCollectionCell.class) forIndexPath:indexPath]; id img = self.imgs[indexPath.row]; if (self.bottleType == THBottleType_Exchange_Picture) { cell.isShowEffect = !self.imgIsSee; cell.img = self.imgIsSee ? img : UIImageMake(@""); return cell; } /* if (需要会员) { cell.isShowEffect = !self.imgIsSee; cell.img = img; return cell; } */ cell.isShowEffect = !self.imgIsSee; cell.img = img; return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { //是否为写真? 会员? //是交换照片? ///查看大图 // if (self.imgItemDidTap) { // // } } //显示图片预览 - (void)showImagePreViewWithSourceView:(UIView *)sourceView { QMUIImagePreviewViewController *imgPreVC = [[QMUIImagePreviewViewController alloc] init]; imgPreVC.sourceImageView = ^UIView * _Nullable{ return sourceView; }; imgPreVC.presentingStyle = QMUIImagePreviewViewControllerTransitioningStyleZoom; [self.qmui_viewController presentViewController:imgPreVC animated:YES completion:nil]; } @end