feat: 更新 EPMomentCell 以支持图片点击查看和点赞功能

主要变更:
1. 引入 SDPhotoBrowser 类,支持点击图片查看大图功能。
2. 更新点赞逻辑,优化点赞状态和数量的显示,移除评论功能。
3. 调整 UI 组件约束,确保点赞按钮的显示效果。
4. 增加图片点击手势识别,提升用户交互体验。

此更新旨在增强动态展示的互动性,简化用户操作流程。
This commit is contained in:
edwinQQQ
2025-10-14 19:01:49 +08:00
parent a8319c61d8
commit f60a0eef14
4 changed files with 93 additions and 42 deletions

View File

@@ -9,6 +9,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@class MomentsInfoModel; @class MomentsInfoModel;
@class SDPhotoBrowser;
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN

View File

@@ -12,8 +12,9 @@
#import "Api+Moments.h" #import "Api+Moments.h"
#import "NetImageView.h" #import "NetImageView.h"
#import "EPEmotionColorStorage.h" #import "EPEmotionColorStorage.h"
#import "SDPhotoBrowser.h"
@interface EPMomentCell () @interface EPMomentCell () <SDPhotoBrowserDelegate>
// MARK: - UI Components // MARK: - UI Components
@@ -125,23 +126,13 @@
make.bottom.equalTo(self.cardView).offset(-8).priority(UILayoutPriorityDefaultHigh); make.bottom.equalTo(self.cardView).offset(-8).priority(UILayoutPriorityDefaultHigh);
}]; }];
// //
[self.actionBar addSubview:self.likeButton]; [self.actionBar addSubview:self.likeButton];
[self.likeButton mas_makeConstraints:^(MASConstraintMaker *make) { [self.likeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.equalTo(self.actionBar).offset(15); make.leading.equalTo(self.actionBar).offset(15);
make.centerY.equalTo(self.actionBar); make.centerY.equalTo(self.actionBar);
make.width.mas_greaterThanOrEqualTo(60); make.width.mas_greaterThanOrEqualTo(80);
}]; }];
//
[self.actionBar addSubview:self.commentButton];
[self.commentButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.actionBar);
make.centerY.equalTo(self.actionBar);
make.width.mas_greaterThanOrEqualTo(60);
}];
//
} }
// MARK: - Public Methods // MARK: - Public Methods
@@ -161,11 +152,11 @@
// //
[self renderImages:model.dynamicResList]; [self renderImages:model.dynamicResList];
// / //
NSInteger likeCnt = MAX(0, model.likeCount.integerValue); NSInteger likeCnt = MAX(0, model.likeCount.integerValue);
NSInteger cmtCnt = MAX(0, model.commentCount.integerValue); self.likeButton.selected = model.isLike;
[self.likeButton setTitle:[NSString stringWithFormat:@"👍 %ld", (long)likeCnt] forState:UIControlStateNormal]; [self.likeButton setTitle:[NSString stringWithFormat:@" %ld", (long)likeCnt] forState:UIControlStateNormal];
[self.commentButton setTitle:[NSString stringWithFormat:@"💬 %ld", (long)cmtCnt] forState:UIControlStateNormal]; [self.likeButton setTitle:[NSString stringWithFormat:@" %ld", (long)likeCnt] forState:UIControlStateSelected];
self.avatarImageView.imageUrl = model.avatar; self.avatarImageView.imageUrl = model.avatar;
@@ -234,6 +225,13 @@
iv.layer.cornerRadius = 6; iv.layer.cornerRadius = 6;
iv.layer.masksToBounds = YES; iv.layer.masksToBounds = YES;
iv.contentMode = UIViewContentModeScaleAspectFill; iv.contentMode = UIViewContentModeScaleAspectFill;
iv.userInteractionEnabled = YES;
iv.tag = i; //
//
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onImageTapped:)];
[iv addGestureRecognizer:tap];
[self.imagesContainer addSubview:iv]; [self.imagesContainer addSubview:iv];
[self.imageViews addObject:iv]; [self.imageViews addObject:iv];
NSInteger row = i / columns; NSInteger row = i / columns;
@@ -289,40 +287,92 @@
- (void)onLikeButtonTapped { - (void)onLikeButtonTapped {
if (!self.currentModel) return; if (!self.currentModel) return;
NSLog(@"[NewMomentCell] 点赞动态: %@", self.currentModel.dynamicId); //
if (self.currentModel.isLike) {
[self performLikeAction:NO];
return;
}
//
if (self.currentModel.status == 0) {
NSLog(@"[EPMomentCell] 动态审核中,无法点赞");
// TODO: Toast
return;
}
//
[self performLikeAction:YES];
}
- (void)performLikeAction:(BOOL)isLike {
NSLog(@"[EPMomentCell] %@ 动态: %@", isLike ? @"点赞" : @"取消点赞", self.currentModel.dynamicId);
NSString *uid = [[AccountInfoStorage instance] getUid]; NSString *uid = [[AccountInfoStorage instance] getUid];
NSString *dynamicId = self.currentModel.dynamicId; NSString *dynamicId = self.currentModel.dynamicId;
NSString *status = self.currentModel.isLike ? @"0" : @"1"; // 0=1= NSString *status = isLike ? @"1" : @"0"; // 0=1=
NSString *likedUid = self.currentModel.uid; NSString *likedUid = self.currentModel.uid;
NSString *worldId = self.currentModel.worldId > 0 ? @(self.currentModel.worldId).stringValue : @""; NSString *worldId = [NSString stringWithFormat:@"%ld", self.currentModel.worldId];
[Api momentsLike:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { [Api momentsLike:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) { if (code == 200) {
// //
self.currentModel.isLike = !self.currentModel.isLike; self.currentModel.isLike = isLike;
NSInteger likeCount = [self.currentModel.likeCount integerValue]; NSInteger likeCount = [self.currentModel.likeCount integerValue];
likeCount += self.currentModel.isLike ? 1 : -1; likeCount += isLike ? 1 : -1;
likeCount = MAX(0, likeCount); //
self.currentModel.likeCount = @(likeCount).stringValue; self.currentModel.likeCount = @(likeCount).stringValue;
// UI // UI
[self.likeButton setTitle:[NSString stringWithFormat:@"👍 %ld", (long)self.currentModel.likeCount] forState:UIControlStateNormal]; self.likeButton.selected = self.currentModel.isLike;
[self.likeButton setTitle:[NSString stringWithFormat:@" %ld", (long)likeCount] forState:UIControlStateNormal];
[self.likeButton setTitle:[NSString stringWithFormat:@" %ld", (long)likeCount] forState:UIControlStateSelected];
NSLog(@"[NewMomentCell] 点赞成功"); NSLog(@"[EPMomentCell] %@ 成功", isLike ? @"点赞" : @"取消点赞");
} else { } else {
NSLog(@"[NewMomentCell] 点赞失败: %@", msg); NSLog(@"[EPMomentCell] %@ 失败: %@", isLike ? @"点赞" : @"取消点赞", msg);
} }
} dynamicId:dynamicId uid:uid status:status likedUid:likedUid worldId:worldId]; } dynamicId:dynamicId uid:uid status:status likedUid:likedUid worldId:worldId];
} }
- (void)onCommentButtonTapped { //
NSLog(@"[NewMomentCell] 评论"); // - (void)onCommentButtonTapped {
// TODO: // NSLog(@"[EPMomentCell] 评论");
// }
- (void)onImageTapped:(UITapGestureRecognizer *)gesture {
if (!self.currentModel || !self.currentModel.dynamicResList.count) return;
NSInteger index = gesture.view.tag;
NSLog(@"[EPMomentCell] 点击图片索引: %ld", (long)index);
SDPhotoBrowser *browser = [[SDPhotoBrowser alloc] init];
browser.sourceImagesContainerView = self.imagesContainer;
browser.delegate = self;
browser.imageCount = self.currentModel.dynamicResList.count;
browser.currentImageIndex = index;
[browser show];
} }
- (void)onShareButtonTapped { #pragma mark - SDPhotoBrowserDelegate
NSLog(@"[NewMomentCell] 分享");
// TODO: - (NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index {
if (index >= 0 && index < self.currentModel.dynamicResList.count) {
id item = self.currentModel.dynamicResList[index];
NSString *url = nil;
if ([item isKindOfClass:[NSDictionary class]]) {
url = [item valueForKey:@"resUrl"] ?: [item valueForKey:@"url"];
} else if ([item respondsToSelector:@selector(resUrl)]) {
url = [item valueForKey:@"resUrl"];
}
if (url) {
return [NSURL URLWithString:url];
}
}
return nil;
}
- (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index {
return [UIImageConstant defaultBannerPlaceholder];
} }
// MARK: - Lazy Loading // MARK: - Lazy Loading
@@ -391,21 +441,20 @@
- (UIButton *)likeButton { - (UIButton *)likeButton {
if (!_likeButton) { if (!_likeButton) {
_likeButton = [self createActionButtonWithTitle:@"👍 0"]; _likeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_likeButton setImage:[UIImage imageNamed:@"monents_info_like_count_normal"] forState:UIControlStateNormal];
[_likeButton setImage:[UIImage imageNamed:@"monents_info_like_count_select"] forState:UIControlStateSelected];
[_likeButton setTitle:@" 0" forState:UIControlStateNormal];
_likeButton.titleLabel.font = [UIFont systemFontOfSize:13];
[_likeButton setTitleColor:[UIColor colorWithWhite:0.5 alpha:1.0] forState:UIControlStateNormal];
[_likeButton setTitleColor:[UIColor colorWithWhite:0.5 alpha:1.0] forState:UIControlStateSelected];
[_likeButton addTarget:self action:@selector(onLikeButtonTapped) forControlEvents:UIControlEventTouchUpInside]; [_likeButton addTarget:self action:@selector(onLikeButtonTapped) forControlEvents:UIControlEventTouchUpInside];
} }
return _likeButton; return _likeButton;
} }
//
- (UIButton *)commentButton { - (UIButton *)commentButton {
if (!_commentButton) {
_commentButton = [self createActionButtonWithTitle:@"💬 0"];
[_commentButton addTarget:self action:@selector(onCommentButtonTapped) forControlEvents:UIControlEventTouchUpInside];
}
return _commentButton;
}
- (UIButton *)shareButton {
return nil; return nil;
} }

View File

@@ -91,8 +91,7 @@
/// @param likedUid uid /// @param likedUid uid
/// @param worldId id /// @param worldId id
+ (void)momentsLike:(HttpRequestHelperCompletion)completion dynamicId:(NSString *)dynamicId uid:(NSString *)uid status:(NSString *)status likedUid:(NSString *)likedUid worldId:(NSString *)worldId { + (void)momentsLike:(HttpRequestHelperCompletion)completion dynamicId:(NSString *)dynamicId uid:(NSString *)uid status:(NSString *)status likedUid:(NSString *)likedUid worldId:(NSString *)worldId {
NSString * fang = [NSString stringFromBase64String:@"ZHluYW1pYy9saWtl"];///dynamic/like [self makeRequest:@"dynamic/like" method:HttpRequestHelperMethodPOST completion:completion, __FUNCTION__, dynamicId, uid, status, likedUid, worldId, nil];
[self makeRequest:fang method:HttpRequestHelperMethodPOST completion:completion, __FUNCTION__, dynamicId, uid, status, likedUid, worldId, nil];
} }
/// ///

View File

@@ -77,6 +77,8 @@ typedef NS_ENUM(NSInteger, MonentsContentType) {
@property (nonatomic, copy) NSString *worldName; @property (nonatomic, copy) NSString *worldName;
///动态的id ///动态的id
@property (nonatomic,copy) NSString *dynamicId; @property (nonatomic,copy) NSString *dynamicId;
///审核状态0=审核中1=通过2=拒绝)
@property (nonatomic, assign) NSInteger status;
///情绪颜色本地标注Hex格式如 #FF0000 ///情绪颜色本地标注Hex格式如 #FF0000
@property (nonatomic, copy) NSString *emotionColor; @property (nonatomic, copy) NSString *emotionColor;
///是否是折叠起来的 ///是否是折叠起来的