This commit is contained in:
2026-01-28 13:43:36 +08:00
parent 51b744ecd7
commit 7d583ceb1d
14 changed files with 152 additions and 36 deletions

View File

@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "comment_nor_icon@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "comment_nor_icon@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 760 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "comment_sel_icon@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "comment_sel_icon@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 705 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -41,7 +41,7 @@ typedef NS_ENUM(NSInteger, KBAIReplyFooterState) {
@property(nonatomic, assign) NSInteger likeCount; @property(nonatomic, assign) NSInteger likeCount;
/// 是否已点赞 /// 是否已点赞
@property(nonatomic, assign) BOOL isLiked; @property(nonatomic, assign) BOOL liked;
/// 创建时间(时间戳) /// 创建时间(时间戳)
@property(nonatomic, assign) NSTimeInterval createTime; @property(nonatomic, assign) NSTimeInterval createTime;

View File

@@ -26,11 +26,6 @@
return @{@"replies" : [KBAIReplyModel class]}; return @{@"replies" : [KBAIReplyModel class]};
} }
- (void)setLiked:(NSInteger)liked {
// NSInteger (0/1) BOOL
_isLiked = (liked == 1);
}
- (void)setCreatedAt:(NSString *)createdAt { - (void)setCreatedAt:(NSString *)createdAt {
// //
if (createdAt && createdAt.length > 0) { if (createdAt && createdAt.length > 0) {
@@ -44,6 +39,28 @@
} }
} }
#pragma mark - MJExtension Hook
/// MJExtension
- (void)mj_didConvertToObjectWithKeyValues:(NSDictionary *)keyValues {
// null
if (!_commentId) {
_commentId = @"";
}
if (!_userId) {
_userId = @"";
}
if (!_userName) {
_userName = @"";
}
if (!_avatarUrl) {
_avatarUrl = @"";
}
if (!_content) {
_content = @"";
}
}
- (instancetype)init { - (instancetype)init {
self = [super init]; self = [super init];
if (self) { if (self) {
@@ -133,7 +150,8 @@
// //
UIFont *contentFont = [UIFont systemFontOfSize:15]; UIFont *contentFont = [UIFont systemFontOfSize:15];
CGRect contentRect = [self.content boundingRectWithSize:CGSizeMake(contentWidth, CGFLOAT_MAX) NSString *contentText = self.content ?: @"";
CGRect contentRect = [contentText boundingRectWithSize:CGSizeMake(contentWidth, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:@{NSFontAttributeName: contentFont} attributes:@{NSFontAttributeName: contentFont}
context:nil]; context:nil];

View File

@@ -7,7 +7,6 @@
#import "KBAIReplyModel.h" #import "KBAIReplyModel.h"
#import <MJExtension/MJExtension.h> #import <MJExtension/MJExtension.h>
#import "KBAIReplyModel.h"
@implementation KBAIReplyModel @implementation KBAIReplyModel
@@ -40,6 +39,31 @@
} }
} }
#pragma mark - MJExtension Hook
/// MJExtension
- (void)mj_didConvertToObjectWithKeyValues:(NSDictionary *)keyValues {
// null
if (!_replyId) {
_replyId = @"";
}
if (!_userId) {
_userId = @"";
}
if (!_userName) {
_userName = @"";
}
if (!_avatarUrl) {
_avatarUrl = @"";
}
if (!_content) {
_content = @"";
}
if (!_replyToUserName) {
_replyToUserName = @"";
}
}
- (NSString *)formattedTime { - (NSString *)formattedTime {
NSDate *date = [NSDate dateWithTimeIntervalSince1970:self.createTime]; NSDate *date = [NSDate dateWithTimeIntervalSince1970:self.createTime];
NSTimeInterval interval = [[NSDate date] timeIntervalSinceDate:date]; NSTimeInterval interval = [[NSDate date] timeIntervalSinceDate:date];
@@ -70,7 +94,7 @@
CGFloat contentWidth = maxWidth - 68 - 28 - 8 - 50; CGFloat contentWidth = maxWidth - 68 - 28 - 8 - 50;
// "回复 @xxx" // "回复 @xxx"
NSMutableString *userNameText = [NSMutableString stringWithString:self.userName]; NSMutableString *userNameText = [NSMutableString stringWithString:self.userName ?: @""];
if (self.replyToUserName.length > 0) { if (self.replyToUserName.length > 0) {
[userNameText appendFormat:@" 回复 @%@", self.replyToUserName]; [userNameText appendFormat:@" 回复 @%@", self.replyToUserName];
} }
@@ -83,7 +107,8 @@
// //
UIFont *contentFont = [UIFont systemFontOfSize:14]; UIFont *contentFont = [UIFont systemFontOfSize:14];
CGRect contentRect = [self.content boundingRectWithSize:CGSizeMake(contentWidth, CGFLOAT_MAX) NSString *contentText = self.content ?: @"";
CGRect contentRect = [contentText boundingRectWithSize:CGSizeMake(contentWidth, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:@{NSFontAttributeName: contentFont} attributes:@{NSFontAttributeName: contentFont}
context:nil]; context:nil];

View File

@@ -29,7 +29,7 @@
#pragma mark - UI Setup #pragma mark - UI Setup
- (void)setupUI { - (void)setupUI {
self.contentView.backgroundColor = [UIColor whiteColor]; self.contentView.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:self.actionButton]; [self.contentView addSubview:self.actionButton];
[self.contentView addSubview:self.lineView]; [self.contentView addSubview:self.lineView];

View File

@@ -35,7 +35,7 @@
#pragma mark - UI Setup #pragma mark - UI Setup
- (void)setupUI { - (void)setupUI {
self.contentView.backgroundColor = [UIColor whiteColor]; self.contentView.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:self.avatarImageView]; [self.contentView addSubview:self.avatarImageView];
[self.contentView addSubview:self.userNameLabel]; [self.contentView addSubview:self.userNameLabel];
@@ -47,7 +47,7 @@
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) { [self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(16); make.left.equalTo(self.contentView).offset(16);
make.top.equalTo(self.contentView).offset(12); make.top.equalTo(self.contentView).offset(12);
make.width.height.mas_equalTo(40); make.width.height.mas_equalTo(28);
}]; }];
[self.userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) { [self.userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
@@ -98,12 +98,11 @@
comment.likeCount > 0 ? [self formatLikeCount:comment.likeCount] : @"赞"; comment.likeCount > 0 ? [self formatLikeCount:comment.likeCount] : @"赞";
self.likeButton.textLabel.text = likeText; self.likeButton.textLabel.text = likeText;
UIImage *likeImage = comment.isLiked UIImage *likeImage = comment.liked
? [UIImage systemImageNamed:@"heart.fill"] ? [UIImage imageNamed:@"comment_sel_icon"]
: [UIImage systemImageNamed:@"heart"]; : [UIImage imageNamed:@"comment_nor_icon"];
self.likeButton.iconView.image = likeImage; self.likeButton.iconView.image = likeImage;
self.likeButton.iconView.tintColor =
comment.isLiked ? [UIColor systemRedColor] : [UIColor grayColor];
} }
- (NSString *)formatLikeCount:(NSInteger)count { - (NSString *)formatLikeCount:(NSInteger)count {
@@ -135,7 +134,7 @@
if (!_avatarImageView) { if (!_avatarImageView) {
_avatarImageView = [[UIImageView alloc] init]; _avatarImageView = [[UIImageView alloc] init];
_avatarImageView.contentMode = UIViewContentModeScaleAspectFill; _avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
_avatarImageView.layer.cornerRadius = 20; _avatarImageView.layer.cornerRadius = 14;
_avatarImageView.layer.masksToBounds = YES; _avatarImageView.layer.masksToBounds = YES;
_avatarImageView.backgroundColor = [UIColor systemGray5Color]; _avatarImageView.backgroundColor = [UIColor systemGray5Color];
} }
@@ -145,8 +144,9 @@
- (UILabel *)userNameLabel { - (UILabel *)userNameLabel {
if (!_userNameLabel) { if (!_userNameLabel) {
_userNameLabel = [[UILabel alloc] init]; _userNameLabel = [[UILabel alloc] init];
_userNameLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium]; _userNameLabel.text = @"--";
_userNameLabel.textColor = [UIColor secondaryLabelColor]; _userNameLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightMedium];
_userNameLabel.textColor = [UIColor colorWithHex:0x9F9F9F];
} }
return _userNameLabel; return _userNameLabel;
} }
@@ -154,8 +154,8 @@
- (UILabel *)contentLabel { - (UILabel *)contentLabel {
if (!_contentLabel) { if (!_contentLabel) {
_contentLabel = [[UILabel alloc] init]; _contentLabel = [[UILabel alloc] init];
_contentLabel.font = [UIFont systemFontOfSize:15]; _contentLabel.font = [UIFont systemFontOfSize:12];
_contentLabel.textColor = [UIColor labelColor]; _contentLabel.textColor = [UIColor whiteColor];
_contentLabel.numberOfLines = 0; _contentLabel.numberOfLines = 0;
} }
return _contentLabel; return _contentLabel;
@@ -165,7 +165,7 @@
if (!_timeLabel) { if (!_timeLabel) {
_timeLabel = [[UILabel alloc] init]; _timeLabel = [[UILabel alloc] init];
_timeLabel.font = [UIFont systemFontOfSize:12]; _timeLabel.font = [UIFont systemFontOfSize:12];
_timeLabel.textColor = [UIColor secondaryLabelColor]; _timeLabel.textColor = [UIColor colorWithHex:0x9F9F9F];
} }
return _timeLabel; return _timeLabel;
} }
@@ -175,7 +175,7 @@
_replyButton = [UIButton buttonWithType:UIButtonTypeCustom]; _replyButton = [UIButton buttonWithType:UIButtonTypeCustom];
_replyButton.titleLabel.font = [UIFont systemFontOfSize:12]; _replyButton.titleLabel.font = [UIFont systemFontOfSize:12];
[_replyButton setTitle:@"回复" forState:UIControlStateNormal]; [_replyButton setTitle:@"回复" forState:UIControlStateNormal];
[_replyButton setTitleColor:[UIColor secondaryLabelColor] forState:UIControlStateNormal]; [_replyButton setTitleColor:[UIColor colorWithHex:0x9F9F9F] forState:UIControlStateNormal];
[_replyButton addTarget:self [_replyButton addTarget:self
action:@selector(replyButtonTapped) action:@selector(replyButtonTapped)
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
@@ -188,10 +188,9 @@
_likeButton = [[KBTopImageButton alloc] init]; _likeButton = [[KBTopImageButton alloc] init];
_likeButton.iconSize = CGSizeMake(20, 20); _likeButton.iconSize = CGSizeMake(20, 20);
_likeButton.spacing = 2; _likeButton.spacing = 2;
_likeButton.iconView.image = [UIImage systemImageNamed:@"heart"]; _likeButton.iconView.image = [UIImage imageNamed:@"comment_nor_icon"];
_likeButton.iconView.tintColor = [UIColor grayColor]; _likeButton.textLabel.font = [UIFont systemFontOfSize:10];
_likeButton.textLabel.font = [UIFont systemFontOfSize:11]; _likeButton.textLabel.textColor = [UIColor colorWithHex:0xC5BEB4];
_likeButton.textLabel.textColor = [UIColor grayColor];
[_likeButton addTarget:self [_likeButton addTarget:self
action:@selector(likeButtonTapped) action:@selector(likeButtonTapped)
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];

View File

@@ -23,6 +23,7 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter";
@interface KBAICommentView () <UITableViewDataSource, UITableViewDelegate> @interface KBAICommentView () <UITableViewDataSource, UITableViewDelegate>
@property(nonatomic, strong) UIVisualEffectView *blurBackgroundView;
@property(nonatomic, strong) UIView *headerView; @property(nonatomic, strong) UIView *headerView;
@property(nonatomic, strong) UILabel *titleLabel; @property(nonatomic, strong) UILabel *titleLabel;
@property(nonatomic, strong) UIButton *closeButton; @property(nonatomic, strong) UIButton *closeButton;
@@ -68,11 +69,18 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter";
#pragma mark - UI Setup #pragma mark - UI Setup
- (void)setupUI { - (void)setupUI {
self.backgroundColor = [UIColor whiteColor]; //
self.backgroundColor = [UIColor clearColor];
self.layer.cornerRadius = 12; self.layer.cornerRadius = 12;
self.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner; self.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
self.clipsToBounds = YES; self.clipsToBounds = YES;
//
[self addSubview:self.blurBackgroundView];
[self.blurBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
[self addSubview:self.headerView]; [self addSubview:self.headerView];
[self.headerView addSubview:self.titleLabel]; [self.headerView addSubview:self.titleLabel];
[self.headerView addSubview:self.closeButton]; [self.headerView addSubview:self.closeButton];
@@ -293,8 +301,8 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter";
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
header.onLikeAction = ^{ header.onLikeAction = ^{
// TODO: // TODO:
comment.isLiked = !comment.isLiked; comment.liked = !comment.liked;
comment.likeCount += comment.isLiked ? 1 : -1; comment.likeCount += comment.liked ? 1 : -1;
[weakSelf.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] [weakSelf.tableView reloadSections:[NSIndexSet indexSetWithIndex:section]
withRowAnimation:UITableViewRowAnimationNone]; withRowAnimation:UITableViewRowAnimationNone];
}; };
@@ -449,10 +457,29 @@ static NSInteger const kRepliesLoadCount = 5;
#pragma mark - Lazy Loading #pragma mark - Lazy Loading
- (UIVisualEffectView *)blurBackgroundView {
if (!_blurBackgroundView) {
// 43pt
// iOS UIBlurEffect API使 dark
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
_blurBackgroundView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
//
// #0000000.31
UIView *darkOverlay = [[UIView alloc] init];
darkOverlay.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.31];
[_blurBackgroundView.contentView addSubview:darkOverlay];
[darkOverlay mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(_blurBackgroundView);
}];
}
return _blurBackgroundView;
}
- (UIView *)headerView { - (UIView *)headerView {
if (!_headerView) { if (!_headerView) {
_headerView = [[UIView alloc] init]; _headerView = [[UIView alloc] init];
_headerView.backgroundColor = [UIColor whiteColor]; _headerView.backgroundColor = [UIColor clearColor];
} }
return _headerView; return _headerView;
} }
@@ -461,7 +488,7 @@ static NSInteger const kRepliesLoadCount = 5;
if (!_titleLabel) { if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init]; _titleLabel = [[UILabel alloc] init];
_titleLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium]; _titleLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
_titleLabel.textColor = [UIColor labelColor]; _titleLabel.textColor = [UIColor whiteColor];
_titleLabel.text = @"0条评论"; _titleLabel.text = @"0条评论";
} }
return _titleLabel; return _titleLabel;
@@ -486,7 +513,7 @@ static NSInteger const kRepliesLoadCount = 5;
style:UITableViewStyleGrouped]; style:UITableViewStyleGrouped];
_tableView.dataSource = self; _tableView.dataSource = self;
_tableView.delegate = self; _tableView.delegate = self;
_tableView.backgroundColor = [UIColor whiteColor]; _tableView.backgroundColor = [UIColor clearColor];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag; _tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;

View File

@@ -29,7 +29,9 @@
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) { if (self) {
self.selectionStyle = UITableViewCellSelectionStyleNone; self.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = [UIColor whiteColor]; self.backgroundColor = [UIColor clearColor];
self.contentView.backgroundColor = [UIColor clearColor];
[self setupUI]; [self setupUI];
} }
return self; return self;

View File

@@ -541,6 +541,7 @@
popStyle:LSTPopStyleSmoothFromBottom popStyle:LSTPopStyleSmoothFromBottom
dismissStyle:LSTDismissStyleSmoothToBottom]; dismissStyle:LSTDismissStyleSmoothToBottom];
customView.popView = popView; customView.popView = popView;
popView.bgColor = [UIColor clearColor];
self.popView = popView; self.popView = popView;
popView.priority = 1000; popView.priority = 1000;
popView.isAvoidKeyboard = NO; popView.isAvoidKeyboard = NO;