Files
keyboard/keyBoard/Class/Home/VC/HomeRankContentVC.m

142 lines
6.0 KiB
Mathematica
Raw Normal View History

2025-11-06 19:19:12 +08:00
//
// HomeRankContentVC.m
// keyBoard
//
// Created by Mac on 2025/11/6.
//
2025-11-06 19:51:50 +08:00
@import UIKit;
2025-11-06 19:19:12 +08:00
#import "HomeRankContentVC.h"
2025-11-11 14:38:38 +08:00
#import "HomeRankDetailPopView.h" //
#import "LSTPopView.h" // LSTPopView
2025-11-06 19:19:12 +08:00
2025-11-06 19:51:50 +08:00
// Cell
#import "HomeRankCardCell.h"
@interface HomeRankContentVC ()
@property (nonatomic, strong) NSArray<NSDictionary *> *dataSource; //
2025-11-06 19:19:12 +08:00
@end
@implementation HomeRankContentVC
- (void)viewDidLoad {
[super viewDidLoad];
2025-11-06 19:51:50 +08:00
self.view.backgroundColor = COLOR_WITH_RGB(246/255.0, 253/255.0, 249/255.0, 1.0); // 绿
//
2025-11-06 19:19:12 +08:00
self.dataSource = @[
2025-11-06 19:51:50 +08:00
@{@"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)}
2025-11-06 19:19:12 +08:00
];
2025-11-06 19:51:50 +08:00
[self.view addSubview:self.collectionView];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
2025-11-06 19:19:12 +08:00
}];
}
2025-11-06 19:51:50 +08:00
- (UICollectionView *)collectionView{
if (!_collectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.sectionInset = UIEdgeInsetsMake(16, 16, 16, 16);
layout.minimumLineSpacing = 24;
layout.minimumInteritemSpacing = 16;
2025-11-06 19:19:12 +08:00
2025-11-06 19:51:50 +08:00
_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;
2025-11-06 19:19:12 +08:00
}
2025-11-06 19:51:50 +08:00
#pragma mark - UICollectionViewDataSource
2025-11-06 19:19:12 +08:00
2025-11-06 19:51:50 +08:00
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.dataSource.count;
2025-11-06 19:19:12 +08:00
}
2025-11-06 19:51:50 +08:00
- (__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];
2025-11-10 15:38:30 +08:00
KBWeakSelf
2025-11-06 19:51:50 +08:00
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;
2025-11-06 19:19:12 +08:00
}
2025-11-06 19:51:50 +08:00
#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
2025-11-11 14:38:38 +08:00
CGFloat totalHInset = 16 + 16;
CGFloat spacing = 16;
CGFloat w = collectionView.bounds.size.width - totalHInset;
2025-11-06 19:51:50 +08:00
CGFloat cellWidth = (w - spacing) / 2.0;
//
2025-11-07 21:57:42 +08:00
CGFloat cellHeight = 234.0;
2025-11-06 19:51:50 +08:00
return CGSizeMake(floor(cellWidth), cellHeight);
2025-11-06 19:19:12 +08:00
}
2025-11-11 14:38:38 +08:00
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
// ->
NSDictionary *d = self.dataSource[indexPath.item];
//
CGFloat width = MIN(KB_SCREEN_WIDTH - 76, 420);
HomeRankDetailPopView *content = [[HomeRankDetailPopView alloc] initWithFrame:CGRectMake(0, 0, width, 460)];
NSString *title = d[@"title"] ?: @"High EQ";
NSString *people = d[@"people"] ?: @"Download: 1 Million";
NSString *desc = @"Be Neither Too Close\nNor Too Distant"; //
[content configWithAvatar:nil title:title download:people desc:desc];
//
LSTPopView *pop = [LSTPopView initWithCustomView:content
parentView:nil
popStyle:LSTPopStyleScale
dismissStyle:LSTDismissStyleScale];
pop.hemStyle = LSTHemStyleCenter; //
pop.bgColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
pop.isClickBgDismiss = YES; //
pop.cornerRadius = 0; // view
__weak typeof(pop) weakPop = pop;
content.saveHandler = ^{ [weakPop dismiss]; };
content.closeHandler = ^{ [weakPop dismiss]; };
[pop pop];
}
2025-11-06 19:19:12 +08:00
#pragma mark - JXCategoryListContentViewDelegate
- (UIView *)listView {
return self.view;
}
2025-11-06 19:51:50 +08:00
2025-11-06 19:19:12 +08:00
@end