This commit is contained in:
2025-11-06 19:51:50 +08:00
parent a72aae84ef
commit 0d13192723
8 changed files with 316 additions and 67 deletions

View File

@@ -48,6 +48,7 @@
047C65452EBCAAAC0035E841 /* carrot_selected.png in Resources */ = {isa = PBXBuildFile; fileRef = 047C651D2EBCAAAC0035E841 /* carrot_selected.png */; };
047C65502EBCBA9E0035E841 /* KBShopVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 047C654F2EBCBA9E0035E841 /* KBShopVC.m */; };
047C65532EBCBAC60035E841 /* KBCommunityVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 047C65522EBCBAC60035E841 /* KBCommunityVC.m */; };
047C65582EBCC06D0035E841 /* HomeRankCardCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 047C65572EBCC06D0035E841 /* HomeRankCardCell.m */; };
04A9FE0F2EB481100020DB6D /* KBHUD.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC97082EB31B14007BD342 /* KBHUD.m */; };
04A9FE132EB4D0D20020DB6D /* KBFullAccessManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 04A9FE112EB4D0D20020DB6D /* KBFullAccessManager.m */; };
04A9FE162EB873C80020DB6D /* UIViewController+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 04A9FE152EB873C80020DB6D /* UIViewController+Extension.m */; };
@@ -182,6 +183,8 @@
047C654F2EBCBA9E0035E841 /* KBShopVC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBShopVC.m; sourceTree = "<group>"; };
047C65512EBCBAC60035E841 /* KBCommunityVC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBCommunityVC.h; sourceTree = "<group>"; };
047C65522EBCBAC60035E841 /* KBCommunityVC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBCommunityVC.m; sourceTree = "<group>"; };
047C65562EBCC06D0035E841 /* HomeRankCardCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HomeRankCardCell.h; sourceTree = "<group>"; };
047C65572EBCC06D0035E841 /* HomeRankCardCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HomeRankCardCell.m; sourceTree = "<group>"; };
04A9A67D2EB9E1690023B8F4 /* KBResponderUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBResponderUtils.h; sourceTree = "<group>"; };
04A9FE102EB4D0D20020DB6D /* KBFullAccessManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBFullAccessManager.h; sourceTree = "<group>"; };
04A9FE112EB4D0D20020DB6D /* KBFullAccessManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBFullAccessManager.m; sourceTree = "<group>"; };
@@ -564,6 +567,8 @@
A1B2E0042EBC7AAA00000001 /* HomeHotCell.m */,
047C650B2EBC8A840035E841 /* KBPanModalView.h */,
047C650C2EBC8A840035E841 /* KBPanModalView.m */,
047C65562EBCC06D0035E841 /* HomeRankCardCell.h */,
047C65572EBCC06D0035E841 /* HomeRankCardCell.m */,
);
path = V;
sourceTree = "<group>";
@@ -1126,6 +1131,7 @@
files = (
04FC95E92EB23B67007BD342 /* KBNetworkManager.m in Sources */,
04FC95D22EB1E7AE007BD342 /* MyVC.m in Sources */,
047C65582EBCC06D0035E841 /* HomeRankCardCell.m in Sources */,
0477BE002EBC6A330055D639 /* HomeRankVC.m in Sources */,
047C650D2EBC8A840035E841 /* KBPanModalView.m in Sources */,
043FBCD22EAF97630036AFE1 /* KBPermissionViewController.m in Sources */,

View File

@@ -0,0 +1,27 @@
//
// HomeRankCardCell.h
// keyBoard
//
// Created by Codex on 2025/11/06.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
/// 首页排行榜卡片 Cell两列
@interface HomeRankCardCell : UICollectionViewCell
/// 点击加号/勾选按钮回调
@property (nonatomic, copy, nullable) void (^onTapAction)(void);
/// 统一配置数据
- (void)configureWithTitle:(NSString *)title
desc:(NSString *)desc
people:(NSString *)people
added:(BOOL)added;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,202 @@
//
// HomeRankCardCell.m
// keyBoard
//
// Created by Codex on 2025/11/06.
//
@import UIKit;
#import "HomeRankCardCell.h"
@interface HomeRankCardCell ()
@property (nonatomic, strong) UIView *shadowView; //
@property (nonatomic, strong) UIView *cardView; //
@property (nonatomic, strong) UIView *badgeCircle; //
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *descLabel;
@property (nonatomic, strong) UILabel *peopleLabel;
@property (nonatomic, strong) UIButton *actionBtn; // /
@property (nonatomic, assign) BOOL added;
@end
@implementation HomeRankCardCell
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.contentView.backgroundColor = UIColor.clearColor;
[self setupUI];
[self setupConstraints];
}
return self;
}
- (void)setupUI {
// 使访
[self.contentView addSubview:self.shadowView];
[self.shadowView addSubview:self.cardView];
[self.contentView addSubview:self.badgeCircle];
[self.cardView addSubview:self.titleLabel];
[self.cardView addSubview:self.descLabel];
[self.cardView addSubview:self.peopleLabel];
[self.cardView addSubview:self.actionBtn];
}
- (void)setupConstraints {
// Masonry
[self.shadowView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.equalTo(self.contentView);
make.top.equalTo(self.contentView.mas_top).offset(36); //
}];
[self.cardView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.shadowView).insets(UIEdgeInsetsMake(0, 8, 0, 8));
}];
[self.badgeCircle mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.cardView);
make.centerY.equalTo(self.shadowView.mas_top);
make.width.height.mas_equalTo(68);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.cardView.mas_top).offset(78);
make.left.equalTo(self.cardView.mas_left).offset(18);
make.right.equalTo(self.cardView.mas_right).offset(-18);
}];
[self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.titleLabel.mas_bottom).offset(12);
make.left.equalTo(self.cardView.mas_left).offset(18);
make.right.equalTo(self.cardView.mas_right).offset(-18);
}];
[self.peopleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.descLabel.mas_bottom).offset(16);
make.left.equalTo(self.cardView.mas_left).offset(18);
make.right.equalTo(self.cardView.mas_right).offset(-18);
}];
[self.actionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.cardView.mas_left).offset(18);
make.right.equalTo(self.cardView.mas_right).offset(-18);
make.bottom.equalTo(self.cardView.mas_bottom).offset(-18);
make.height.mas_equalTo(56);
}];
}
- (void)layoutSubviews {
[super layoutSubviews];
//
_shadowView.layer.shadowColor = [UIColor colorWithWhite:0 alpha:0.15].CGColor;
_shadowView.layer.shadowOpacity = 1.0;
_shadowView.layer.shadowRadius = 10.0;
_shadowView.layer.shadowOffset = CGSizeMake(0, 6);
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:_cardView.bounds cornerRadius:18.0];
_shadowView.layer.shadowPath = path.CGPath;
_badgeCircle.layer.cornerRadius = 34;
}
- (void)prepareForReuse {
[super prepareForReuse];
self.onTapAction = nil;
}
- (void)tapAction {
if (self.onTapAction) self.onTapAction();
}
- (void)configureWithTitle:(NSString *)title desc:(NSString *)desc people:(NSString *)people added:(BOOL)added {
self.added = added;
self.titleLabel.text = title ?: @"";
self.descLabel.text = desc ?: @"";
self.peopleLabel.text = people ?: @"";
if (added) {
//
self.actionBtn.backgroundColor = [UIColor colorWithWhite:0.93 alpha:1.0];
[self.actionBtn setTitle:@"✓" forState:UIControlStateNormal];
[self.actionBtn setTitleColor:[UIColor colorWithWhite:0.55 alpha:1.0] forState:UIControlStateNormal];
} else {
//
self.actionBtn.backgroundColor = [UIColor blackColor];
[self.actionBtn setTitle:@"+" forState:UIControlStateNormal];
[self.actionBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
}
#pragma mark - Lazy UI
- (UIView *)shadowView {
if (!_shadowView) {
_shadowView = [UIView new];
_shadowView.backgroundColor = UIColor.clearColor;
}
return _shadowView;
}
- (UIView *)cardView {
if (!_cardView) {
_cardView = [UIView new];
_cardView.backgroundColor = UIColor.whiteColor;
_cardView.layer.cornerRadius = 18.0;
_cardView.layer.masksToBounds = YES;
}
return _cardView;
}
- (UIView *)badgeCircle {
if (!_badgeCircle) {
_badgeCircle = [UIView new];
_badgeCircle.backgroundColor = UIColor.whiteColor;
_badgeCircle.layer.borderColor = [UIColor colorWithRed:0.78 green:0.90 blue:0.20 alpha:1.0].CGColor;
_badgeCircle.layer.borderWidth = 3.0;
}
return _badgeCircle;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [UILabel new];
_titleLabel.textColor = [UIColor colorWithWhite:0 alpha:0.95];
_titleLabel.font = [UIFont systemFontOfSize:26 weight:UIFontWeightSemibold];
_titleLabel.textAlignment = NSTextAlignmentCenter;
}
return _titleLabel;
}
- (UILabel *)descLabel {
if (!_descLabel) {
_descLabel = [UILabel new];
_descLabel.textColor = [UIColor colorWithWhite:0.45 alpha:1];
_descLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightRegular];
_descLabel.textAlignment = NSTextAlignmentCenter;
_descLabel.numberOfLines = 2;
}
return _descLabel;
}
- (UILabel *)peopleLabel {
if (!_peopleLabel) {
_peopleLabel = [UILabel new];
_peopleLabel.textColor = [UIColor colorWithRed:0.31 green:0.78 blue:0.63 alpha:1.0];
_peopleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightSemibold];
_peopleLabel.textAlignment = NSTextAlignmentCenter;
_peopleLabel.numberOfLines = 2;
}
return _peopleLabel;
}
- (UIButton *)actionBtn {
if (!_actionBtn) {
_actionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_actionBtn.layer.cornerRadius = 12.0;
_actionBtn.layer.masksToBounds = YES;
[_actionBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
_actionBtn.titleLabel.font = [UIFont systemFontOfSize:28 weight:UIFontWeightSemibold];
[_actionBtn addTarget:self action:@selector(tapAction) forControlEvents:UIControlEventTouchUpInside];
}
return _actionBtn;
}
@end

View File

@@ -103,7 +103,7 @@
if (self.currentIndex == 0) {
return self.hotVC.tableView;
}
return self.rankVC.tableView;
return self.rankVC.collectionView;
}
//

View File

@@ -10,8 +10,8 @@
NS_ASSUME_NONNULL_BEGIN
@interface HomeRankContentVC : UIViewController<JXCategoryListContentViewDelegate>
@property (nonatomic, strong) BaseTableView *tableView;
@interface HomeRankContentVC : UIViewController<JXCategoryListContentViewDelegate, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) UICollectionView *collectionView;
@end

View File

@@ -5,93 +5,107 @@
// Created by Mac on 2025/11/6.
//
@import UIKit;
#import "HomeRankContentVC.h"
#import "HomeHotCell.h"
@interface HomeRankContentVC () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) NSArray<NSDictionary *> *dataSource; //
// Cell
#import "HomeRankCardCell.h"
@interface HomeRankContentVC ()
@property (nonatomic, strong) NSArray<NSDictionary *> *dataSource; //
@end
@implementation HomeRankContentVC
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
//
self.dataSource = @[
@{@"rank":@4, @"title":@"Ambiguous", @"sub":@"Be Neither Too Close Nor Too Distant, Want To ...", @"joined":@NO},
@{@"rank":@5, @"title":@"Ambiguous", @"sub":@"Be Neither Too Close Nor Too Distant, Want To ...", @"joined":@YES},
@{@"rank":@6, @"title":@"Ambiguous", @"sub":@"Be Neither Too Close Nor Too Distant, Want To ...", @"joined":@NO},
@{@"rank":@7, @"title":@"Ambiguous", @"sub":@"Be Neither Too Close Nor Too Distant, Want To ...", @"joined":@NO},
@{@"rank":@4, @"title":@"Ambiguous", @"sub":@"Be Neither Too Close Nor Too Distant, Want To ...", @"joined":@NO},
@{@"rank":@5, @"title":@"Ambiguous", @"sub":@"Be Neither Too Close Nor Too Distant, Want To ...", @"joined":@YES},
@{@"rank":@6, @"title":@"Ambiguous", @"sub":@"Be Neither Too Close Nor Too Distant, Want To ...", @"joined":@NO},
@{@"rank":@7, @"title":@"Ambiguous", @"sub":@"Be Neither Too Close Nor Too Distant, Want To ...", @"joined":@NO},
@{@"rank":@4, @"title":@"Ambiguous", @"sub":@"Be Neither Too Close Nor Too Distant, Want To ...", @"joined":@NO},
@{@"rank":@5, @"title":@"Ambiguous", @"sub":@"Be Neither Too Close Nor Too Distant, Want To ...", @"joined":@YES},
@{@"rank":@6, @"title":@"Ambiguous", @"sub":@"Be Neither Too Close Nor Too Distant, Want To ...", @"joined":@NO},
@{@"rank":@7, @"title":@"Ambiguous", @"sub":@"Be Neither Too Close Nor Too Distant, Want To ...", @"joined":@NO}
];
//
self.view.backgroundColor = COLOR_WITH_RGB(arc4random()%255/255.0, arc4random()%255/255.0, arc4random()%255/255.0, 1);
[self.view addSubview:self.tableView];
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.right.equalTo(self.view);
make.bottom.equalTo(self.view);
self.view.backgroundColor = COLOR_WITH_RGB(246/255.0, 253/255.0, 249/255.0, 1.0); // 绿
//
self.dataSource = @[
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(NO)},
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(YES)},
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(NO)},
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(YES)},
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(NO)},
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(YES)},
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(NO)},
@{@"title":@"High EQ", @"desc":@"Be Neither Too Close\nNor Too Distant...", @"people":@"Two Million People\nHave Used It", @"added":@(YES)}
];
[self.view addSubview:self.collectionView];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
}
#pragma mark - UITableViewDataSource
- (UICollectionView *)collectionView{
if (!_collectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.sectionInset = UIEdgeInsetsMake(16, 16, 16, 16);
layout.minimumLineSpacing = 24;
layout.minimumInteritemSpacing = 16;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.backgroundColor = [UIColor clearColor];
// _collectionView.alwaysBounceVertical = YES;
_collectionView.bounces = false;
_collectionView.dataSource = self;
_collectionView.delegate = self;
[_collectionView registerClass:[HomeRankCardCell class] forCellWithReuseIdentifier:@"HomeRankCardCell"];
// self.collectionView.translatesAutoresizingMaskIntoConstraints = NO;
}
return _collectionView;
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
HomeHotCell *cell = [tableView dequeueReusableCellWithIdentifier:HomeHotCell.reuseId forIndexPath:indexPath];
NSDictionary *item = self.dataSource[indexPath.row];
// cell
[cell configWithRank:[item[@"rank"] integerValue]
title:item[@"title"]
subtitle:item[@"sub"]
joined:[item[@"joined"] boolValue]];
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
HomeRankCardCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeRankCardCell" forIndexPath:indexPath];
NSDictionary *d = self.dataSource[indexPath.item];
BOOL added = [d[@"added"] boolValue];
[cell configureWithTitle:d[@"title"]
desc:d[@"desc"]
people:d[@"people"]
added:added];
__weak typeof(self) weakSelf = self;
cell.onTapAction = ^{
// /
NSMutableArray *m = [weakSelf.dataSource mutableCopy];
NSMutableDictionary *md = [m[indexPath.item] mutableCopy];
BOOL cur = [md[@"added"] boolValue];
md[@"added"] = @(!cur);
m[indexPath.item] = md;
weakSelf.dataSource = [m copy];
[weakSelf.collectionView reloadItemsAtIndexPaths:@[indexPath]];
};
return cell;
}
#pragma mark - UITableViewDelegate
#pragma mark - UICollectionViewDelegateFlowLayout
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 84.0;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (BaseTableView *)tableView {
if (!_tableView) {
// 使 BaseTableView
_tableView = [[BaseTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableView.dataSource = self;
_tableView.delegate = self;
_tableView.bounces = false;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone; // 线
_tableView.showsVerticalScrollIndicator = NO;
_tableView.contentInset = UIEdgeInsetsMake(8, 0, KB_SafeAreaBottom(), 0);
[_tableView registerClass:HomeHotCell.class forCellReuseIdentifier:HomeHotCell.reuseId];
}
return _tableView;
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGFloat totalHInset = 16 + 16; // section i/l/r
CGFloat spacing = 16; // interitem spacing
CGFloat w = collectionView.bounds.size.width - totalHInset; // not including section insets yet
// Two columns each width = (width - spacing - lr insets)/2
CGFloat cellWidth = (w - spacing) / 2.0;
//
CGFloat cellHeight = 340.0;
return CGSizeMake(floor(cellWidth), cellHeight);
}
#pragma mark - JXCategoryListContentViewDelegate
/**
<JXCategoryListContentViewDelegate>
*/
- (UIView *)listView {
return self.view;
}
@end

View File

@@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface HomeRankVC : UIViewController<JXCategoryListContainerViewDelegate>
// 列表
@property (nonatomic, strong) BaseTableView *tableView;
@property (nonatomic, strong) UICollectionView *collectionView;
@end
NS_ASSUME_NONNULL_END

View File

@@ -131,7 +131,7 @@
// <JXCategoryListContentViewDelegate>
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
HomeRankContentVC *list = [[HomeRankContentVC alloc] init];
self.tableView = list.tableView;
self.collectionView = list.collectionView;
return list;
}