1
This commit is contained in:
@@ -1,14 +1,6 @@
|
||||
//
|
||||
// KBSkinDetailVC.m
|
||||
// keyBoard
|
||||
//
|
||||
// 皮肤详情页(UICollectionView 实现)
|
||||
// 结构:
|
||||
// - Section0:顶部大卡片(上图,下方左右两段文案)
|
||||
// - Section1:标签容器 cell(内部再嵌套一个 collectionView 以展示 Cute/Fresh 等标签)
|
||||
// - Section2:区块标题 cell(例如 “Recommended Skin”)
|
||||
// - Section3:推荐皮肤 2 列网格(使用已有 KBSkinCardCell)
|
||||
//
|
||||
|
||||
#import "KBSkinDetailVC.h"
|
||||
#import <Masonry/Masonry.h>
|
||||
|
||||
@@ -2,17 +2,12 @@
|
||||
// MySkinVC.m
|
||||
// keyBoard
|
||||
//
|
||||
// 我的皮肤列表页(支持编辑多选删除)。
|
||||
// 需求要点:
|
||||
// - 顶部右侧 Editor/Cancel 切换
|
||||
// - CollectionView Masonry 约束 + 懒加载控件
|
||||
// - 自定义 cell,编辑态显示左上角选择圆点,支持多选
|
||||
// - 底部 bottomView 展示已选择数量与删除按钮,数量>0 时 Delete 变为 #02BEAC 可点
|
||||
//
|
||||
|
||||
#import "MySkinVC.h"
|
||||
#import <Masonry/Masonry.h>
|
||||
#import "UIColor+Extension.h"
|
||||
#import <MJRefresh/MJRefresh.h>
|
||||
#import "UIScrollView+KBEmptyView.h" // 统一空态封装(LYEmptyView)
|
||||
|
||||
#import "MySkinCell.h"
|
||||
|
||||
@@ -25,6 +20,7 @@ static NSString * const kMySkinCellId = @"kMySkinCellId";
|
||||
@property (nonatomic, strong) UIButton *deleteButton; // 删除
|
||||
|
||||
@property (nonatomic, strong) NSMutableArray<NSDictionary *> *data; // 简单数据源
|
||||
@property (nonatomic, assign) NSInteger loadCount; // 刷新计数(用于演示空/有数据切换)
|
||||
@property (nonatomic, assign, getter=isEditingMode) BOOL editingMode; // 是否编辑态
|
||||
@end
|
||||
|
||||
@@ -39,13 +35,8 @@ static NSString * const kMySkinCellId = @"kMySkinCellId";
|
||||
// 右上角 Editor/Cancel
|
||||
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Editor" style:UIBarButtonItemStylePlain target:self action:@selector(onToggleEdit)];
|
||||
|
||||
// 数据源(演示用)
|
||||
self.data = [@[
|
||||
@{ @"title": @"Dopamine" },
|
||||
@{ @"title": @"Dopamine" },
|
||||
@{ @"title": @"Dopamine" },
|
||||
@{ @"title": @"Dopamine" },
|
||||
] mutableCopy];
|
||||
// 数据源初始化为空(演示空态 + 下拉刷新)
|
||||
self.data = [NSMutableArray array];
|
||||
|
||||
// 视图
|
||||
[self.view addSubview:self.collectionView];
|
||||
@@ -63,10 +54,50 @@ static NSString * const kMySkinCellId = @"kMySkinCellId";
|
||||
make.height.mas_equalTo(64);
|
||||
}];
|
||||
|
||||
// 空态视图(LYEmptyView)统一样式 + 重试按钮
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[self.collectionView kb_makeDefaultEmptyViewWithImage:nil
|
||||
title:@"暂无皮肤"
|
||||
detail:@"下拉刷新试试"
|
||||
buttonTitle:@"重试"
|
||||
tapHandler:nil
|
||||
buttonHandler:^{ [weakSelf.collectionView.mj_header beginRefreshing]; }];
|
||||
[self.collectionView kb_setLYAutoShowEnabled:NO]; // 采用手动控制显隐
|
||||
|
||||
// 立即按当前数据源状态显示一次空态(首屏就应展示空视图)
|
||||
[self.collectionView kb_endLoadingForEmpty];
|
||||
|
||||
// 下拉刷新(演示网络加载 + 空态切换)
|
||||
self.collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(fetchData)];
|
||||
|
||||
// 首次进入自动刷新
|
||||
[self.collectionView.mj_header beginRefreshing];
|
||||
|
||||
// 初始:非编辑态,隐藏底部
|
||||
self.bottomView.hidden = YES;
|
||||
}
|
||||
|
||||
#pragma mark - Data
|
||||
|
||||
- (void)fetchData {
|
||||
// 模拟网络延迟 1.0s
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
self.loadCount += 1;
|
||||
|
||||
// 交替返回:奇数次空数据,偶数次有数据(演示空态/非空切换)
|
||||
[self.data removeAllObjects];
|
||||
if (self.loadCount % 2 == 0) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
[self.data addObject:@{ @"title": @"Dopamine" }];
|
||||
}
|
||||
}
|
||||
|
||||
[self.collectionView reloadData];
|
||||
[self.collectionView kb_endLoadingForEmpty]; // 根据数据源显示/隐藏 emptyView
|
||||
[self.collectionView.mj_header endRefreshing];
|
||||
});
|
||||
}
|
||||
|
||||
#pragma mark - Actions
|
||||
|
||||
- (void)onToggleEdit {
|
||||
@@ -112,6 +143,8 @@ static NSString * const kMySkinCellId = @"kMySkinCellId";
|
||||
[self.collectionView deleteItemsAtIndexPaths:selected];
|
||||
} completion:^(BOOL finished) {
|
||||
[self updateBottomUI];
|
||||
// 根据当前数据源显隐空视图(删除到 0 条时应显示空态)
|
||||
[self.collectionView kb_endLoadingForEmpty];
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
@@ -29,10 +29,10 @@
|
||||
}
|
||||
|
||||
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
|
||||
// MySkinVC *vc = [[MySkinVC alloc] init];
|
||||
KBSkinDetailVC *vc = [[KBSkinDetailVC alloc] init];
|
||||
MySkinVC *vc = [[MySkinVC alloc] init];
|
||||
// KBSkinDetailVC *vc = [[KBSkinDetailVC alloc] init];
|
||||
|
||||
// [self.navigationController pushViewController:vc animated:true];
|
||||
[self.navigationController pushViewController:vc animated:true];
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user