1
This commit is contained in:
@@ -23,6 +23,7 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter";
|
||||
|
||||
@interface KBAICommentView () <UITableViewDataSource, UITableViewDelegate>
|
||||
|
||||
@property(nonatomic, strong) UIVisualEffectView *blurBackgroundView;
|
||||
@property(nonatomic, strong) UIView *headerView;
|
||||
@property(nonatomic, strong) UILabel *titleLabel;
|
||||
@property(nonatomic, strong) UIButton *closeButton;
|
||||
@@ -68,11 +69,18 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter";
|
||||
#pragma mark - UI Setup
|
||||
|
||||
- (void)setupUI {
|
||||
self.backgroundColor = [UIColor whiteColor];
|
||||
// 设置背景为透明,让模糊效果可见
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
self.layer.cornerRadius = 12;
|
||||
self.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
|
||||
self.clipsToBounds = YES;
|
||||
|
||||
// 添加模糊背景(最底层)
|
||||
[self addSubview:self.blurBackgroundView];
|
||||
[self.blurBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.equalTo(self);
|
||||
}];
|
||||
|
||||
[self addSubview:self.headerView];
|
||||
[self.headerView addSubview:self.titleLabel];
|
||||
[self.headerView addSubview:self.closeButton];
|
||||
@@ -293,8 +301,8 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter";
|
||||
__weak typeof(self) weakSelf = self;
|
||||
header.onLikeAction = ^{
|
||||
// TODO: 处理点赞逻辑
|
||||
comment.isLiked = !comment.isLiked;
|
||||
comment.likeCount += comment.isLiked ? 1 : -1;
|
||||
comment.liked = !comment.liked;
|
||||
comment.likeCount += comment.liked ? 1 : -1;
|
||||
[weakSelf.tableView reloadSections:[NSIndexSet indexSetWithIndex:section]
|
||||
withRowAnimation:UITableViewRowAnimationNone];
|
||||
};
|
||||
@@ -449,10 +457,29 @@ static NSInteger const kRepliesLoadCount = 5;
|
||||
|
||||
#pragma mark - Lazy Loading
|
||||
|
||||
- (UIVisualEffectView *)blurBackgroundView {
|
||||
if (!_blurBackgroundView) {
|
||||
// 创建模糊效果(43pt 的模糊半径)
|
||||
// iOS 的 UIBlurEffect 没有直接设置模糊半径的 API,使用系统预设的 dark 效果
|
||||
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
|
||||
_blurBackgroundView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
|
||||
|
||||
// 在模糊效果上叠加一个半透明黑色遮罩来调整透明度和颜色
|
||||
// 颜色:#000000,透明度:0.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 {
|
||||
if (!_headerView) {
|
||||
_headerView = [[UIView alloc] init];
|
||||
_headerView.backgroundColor = [UIColor whiteColor];
|
||||
_headerView.backgroundColor = [UIColor clearColor];
|
||||
}
|
||||
return _headerView;
|
||||
}
|
||||
@@ -461,7 +488,7 @@ static NSInteger const kRepliesLoadCount = 5;
|
||||
if (!_titleLabel) {
|
||||
_titleLabel = [[UILabel alloc] init];
|
||||
_titleLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
|
||||
_titleLabel.textColor = [UIColor labelColor];
|
||||
_titleLabel.textColor = [UIColor whiteColor];
|
||||
_titleLabel.text = @"0条评论";
|
||||
}
|
||||
return _titleLabel;
|
||||
@@ -486,7 +513,7 @@ static NSInteger const kRepliesLoadCount = 5;
|
||||
style:UITableViewStyleGrouped];
|
||||
_tableView.dataSource = self;
|
||||
_tableView.delegate = self;
|
||||
_tableView.backgroundColor = [UIColor whiteColor];
|
||||
_tableView.backgroundColor = [UIColor clearColor];
|
||||
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
||||
_tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user