Commit 6ba7991a authored by 艾娇平's avatar 艾娇平

Merge branch 'ajp/dev' into 'master'

让JXPageView支持多组数据展示

See merge request !34
parents 2e30e00c aa147bcc
......@@ -32,7 +32,6 @@
*/
- (UIScrollView *)listScrollView;
/**
当listView内部持有的UIScrollView或UITableView或UICollectionView的代理方法`scrollViewDidScroll`回调时,需要调用该代理方法传入的callback
......@@ -51,6 +50,11 @@
@protocol JXPagerViewDelegate <NSObject>
- (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index;
- (void)pagerView:(JXPagerView *)pagerView didScroll:(NSInteger)row;
@optional
/**
返回tableHeaderView的高度,因为内部需要比对判断,只能是整型数
......@@ -59,7 +63,6 @@
*/
- (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView;
/**
返回tableHeaderView
......@@ -68,7 +71,6 @@
*/
- (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView;
/**
返回悬浮HeaderView的高度,因为内部需要比对判断,只能是整型数
......@@ -77,7 +79,6 @@
*/
- (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView;
/**
返回悬浮HeaderView。我用的是自己封装的JXCategoryView(Github:https://github.com/pujiaxin33/JXCategoryView),你也可以选择其他的三方库或者自己写
......@@ -102,14 +103,8 @@
@param index index description
@return 新生成的列表实例
*/
- (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index;
- (void)pagerView:(JXPagerView *)pagerView didScroll:(NSInteger)row;
@optional
/**
返回tableHeaderView 距离pagerView顶部的距离 默认为 0
*/
- (CGFloat)tableViewSectionHeaderViewContentYInPagerView:(JXPagerView *)pagerView;
/**
......@@ -123,7 +118,7 @@
- (void)mainTableViewWillBeginDragging:(UIScrollView *)scrollView;
/**
@param 由于 mainTableViewDidScroll 滚动偏移量返回的最大值为headerView的高度, 这个偏移量加上子ScrollView的偏移量。
由于 mainTableViewDidScroll 滚动偏移量返回的最大值为headerView的高度, 这个偏移量加上子ScrollView的偏移量。
*/
- (void)listAndMainScrollViewDidScroll:(CGFloat)contentOffsetY;
......@@ -135,7 +130,7 @@
@property (nonatomic, strong) JXPagerMainTableView *mainTableView;
@property (nonatomic, strong, readonly) JXPagerListContainerView *listContainerView;
@property (nonatomic, strong) JXPagerListContainerView *listContainerView;
- (instancetype)initWithDelegate:(id<JXPagerViewDelegate>)delegate NS_DESIGNATED_INITIALIZER;
......@@ -166,9 +161,19 @@
@property (nonatomic, strong, readonly) NSDictionary <NSNumber *, id<JXPagerViewListViewDelegate>> *validListDict; //暴露给子类使用,请勿直接使用该属性!当前已经加载过可用的列表字典,key就是index值,value是对应的列表。
- (void)preferredProcessListViewDidScroll:(UIScrollView *)scrollView;
- (void)preferredProcessMainTableViewDidScroll:(UIScrollView *)scrollView;
// 获取listContainer的Cell
- (UITableViewCell *)listContainerCellForRowAtIndexPath:(NSIndexPath *)indexPath;
- (CGFloat)listContainerCellHeight;
#pragma mark - UIScrollViewDelegate
/// 直接调用JXPagerView 内部的滑动代理实现
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView;
@end
......@@ -7,13 +7,15 @@
//
#import "JXPagerView.h"
static NSString *const kGM_ListCellIdentifier = @"gm_ListCellIdentifier";
@import GMRefresh;
@interface JXPagerView () <UITableViewDataSource, UITableViewDelegate, JXPagerListContainerViewDelegate>
//@property (nonatomic, strong) JXPagerMainTableView *mainTableView;
@property (nonatomic, strong) JXPagerListContainerView *listContainerView;
@property (nonatomic, strong) UIScrollView *currentScrollingListView;
@property (nonatomic, weak) id<JXPagerViewListViewDelegate> currentList;
@property (nonatomic, strong) UITableViewCell *listContainerCell;
@property (nonatomic, strong) NSMutableDictionary <NSNumber *, id<JXPagerViewListViewDelegate>> *validListDict;
@property (nonatomic, assign) CGFloat mainViewScrollOffsetY;
@property (nonatomic, assign) BOOL isListScroll;
......@@ -41,7 +43,7 @@
self.mainTableView.dataSource = self;
self.mainTableView.delegate = self;
[self refreshTableHeaderView];
[self.mainTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
[self.mainTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kGM_ListCellIdentifier];
if (@available(iOS 11.0, *)) {
self.mainTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
......@@ -67,25 +69,24 @@
- (void)reloadData {
self.currentList = nil;
self.currentScrollingListView = nil;
self.listContainerCell = nil;
for (id<JXPagerViewListViewDelegate> list in self.validListDict.allValues) {
[list.listView removeFromSuperview];
}
[_validListDict removeAllObjects];
[self refreshTableHeaderView];
[self.mainTableView reloadData];
[self.listContainerView reloadData];
}
- (void)refreshTableHeaderView {
UIView *tableHeaderView = [self.delegate tableHeaderViewInPagerView:self];
// UIView *containerView = [[UIView alloc] initWithFrame:tableHeaderView.bounds];
// [containerView addSubview:tableHeaderView];
self.mainTableView.tableHeaderView = tableHeaderView;
if ([self.delegate respondsToSelector:@selector(tableHeaderViewInPagerView:)]) {
UIView *tableHeaderView = [self.delegate tableHeaderViewInPagerView:self];
self.mainTableView.tableHeaderView = tableHeaderView;
}
}
- (void)preferredProcessListViewDidScroll:(UIScrollView *)scrollView {
CGFloat listScrollOffsetY = scrollView.contentOffset.y;
if ([self.delegate respondsToSelector:@selector(listAndMainScrollViewDidScroll:)]) {
......@@ -135,10 +136,31 @@
[self preferredProcessListViewDidScroll:scrollView];
}
- (UITableViewCell *)listContainerCellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = self.listContainerCell;
if (!cell) {
cell = [self.mainTableView dequeueReusableCellWithIdentifier:kGM_ListCellIdentifier forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
self.listContainerCell = cell;
for (UIView *view in cell.contentView.subviews) {
[view removeFromSuperview];
}
self.listContainerView.frame = CGRectMake(0, 0, cell.contentView.bounds.size.width, cell.contentView.bounds.size.height);
[cell.contentView addSubview:self.listContainerView];
}
return cell;
}
- (CGFloat)listContainerCellHeight {
return self.bounds.size.height;
}
#pragma mark - UITableViewDataSource, UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
......@@ -149,13 +171,8 @@
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
for (UIView *view in cell.contentView.subviews) {
[view removeFromSuperview];
}
self.listContainerView.frame = cell.contentView.bounds;
[cell.contentView addSubview:self.listContainerView];
return cell;
return [self listContainerCellForRowAtIndexPath:indexPath];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
......@@ -175,41 +192,37 @@
footer.backgroundColor = [UIColor clearColor];
return footer;
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (self.mainTableView.mj_header.refreshing) {
return;
}
CGFloat sectionHeaderHeight = [self.delegate heightForPinSectionHeaderInPagerView:self];
CGFloat sectionHeaderHeight = 0;
if ([self.delegate respondsToSelector:@selector(heightForPinSectionHeaderInPagerView:)]) {
sectionHeaderHeight = [self.delegate heightForPinSectionHeaderInPagerView:self];
}
CGFloat sectionHeaderContentY = 0;
if ([self.delegate respondsToSelector:@selector(tableViewSectionHeaderViewContentYInPagerView:)]) {
sectionHeaderContentY = [self.delegate tableViewSectionHeaderViewContentYInPagerView:self];
}
CGFloat ceilPositon = [self.delegate tableHeaderViewHeightInPagerView:self] -sectionHeaderHeight - sectionHeaderContentY;
if (scrollView.contentOffset.y < sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
}
if (scrollView.contentOffset.y>=ceilPositon && scrollView.contentOffset.y>=sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(sectionHeaderContentY, 0, 0, 0);
scrollView.contentInset = UIEdgeInsetsMake(sectionHeaderContentY, 0, 0, 0);
}
CGFloat offsetY = scrollView.contentOffset.y;
self.mainViewScrollOffsetY = offsetY;
if ([self.delegate respondsToSelector:@selector(mainTableViewDidScroll:)]) {
[self.delegate mainTableViewDidScroll:scrollView];
}
if (scrollView.isTracking && self.isListHorizontalScrollEnabled) {
self.listContainerView.collectionView.scrollEnabled = NO;
}
[self preferredProcessMainTableViewDidScroll:scrollView];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment