171 lines
6.4 KiB
Objective-C
171 lines
6.4 KiB
Objective-C
//
|
|
// YMMineHeadItemTableViewCell.m
|
|
// YUMI
|
|
//
|
|
// Created by YUMI on 2022/1/19.
|
|
//
|
|
|
|
#import "XPMineHeadItemTableViewCell.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "DJDKMIMOMColor.h"
|
|
#import "YUMIMacroUitls.h"
|
|
#import "NSArray+Safe.h"
|
|
///View
|
|
#import "XPMineHeadItemCollectionViewCell.h"
|
|
#import "XPMineHeadFunctionItemLayout.h"
|
|
|
|
@interface XPMineHeadItemTableViewCell ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
|
|
///列表
|
|
@property (nonatomic,strong) UICollectionView *collectionView;
|
|
|
|
@property (nonatomic, strong) UIView *mainView;
|
|
@property (nonatomic, strong) UIView *slideBackView;
|
|
@property (nonatomic, strong) UIView *sliderView;
|
|
|
|
@end
|
|
|
|
|
|
@implementation XPMineHeadItemTableViewCell
|
|
|
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
|
|
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
return self;
|
|
}
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
self.backgroundColor = [UIColor clearColor];
|
|
[self.contentView addSubview:self.mainView];
|
|
[self.mainView addSubview:self.collectionView];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.mas_equalTo(self.contentView).inset(15);
|
|
make.top.bottom.mas_equalTo(self.contentView);
|
|
}];
|
|
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(14);
|
|
make.leading.trailing.mas_equalTo(self.mainView);
|
|
make.height.mas_equalTo(77+32+17+6);
|
|
}];
|
|
}
|
|
|
|
#pragma mark - UICollectionViewDatasource And UICollectionViewDelegate
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
return self.datasource.count;
|
|
}
|
|
|
|
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
XPMineHeadItemCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPMineHeadItemCollectionViewCell class]) forIndexPath:indexPath];
|
|
XPMineFunctionItemModel * item = [self.datasource xpSafeObjectAtIndex:indexPath.row];
|
|
cell.itemModel = item;
|
|
return cell;
|
|
}
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
[collectionView deselectItemAtIndexPath:indexPath animated:YES];
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineHeadItemTableViewCell:didSelectItem:)]) {
|
|
XPMineFunctionItemModel * model = [self.datasource xpSafeObjectAtIndex:indexPath.row];
|
|
[self.delegate xPMineHeadItemTableViewCell:self didSelectItem:model];
|
|
}
|
|
}
|
|
|
|
#pragma mark - MSBaseRTLFlowLayout
|
|
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
|
|
return 0;
|
|
}
|
|
|
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
CGFloat width = (KScreenWidth - 30) / 4;
|
|
return CGSizeMake(width, 32+4+17+6);
|
|
}
|
|
|
|
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
|
|
return 0;
|
|
}
|
|
|
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
|
CGPoint offset = scrollView.contentOffset;
|
|
CGRect frame = self.sliderView.frame;
|
|
frame.origin.x = offset.x*12/(scrollView.contentSize.width-scrollView.frame.size.width);
|
|
self.sliderView.frame = frame;
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setDatasource:(NSArray<XPMineFunctionItemModel *> *)datasource {
|
|
_datasource = datasource;
|
|
if(datasource.count > 8) {
|
|
[self.mainView addSubview:self.slideBackView];
|
|
[self.slideBackView addSubview:self.sliderView];
|
|
[self.slideBackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.mas_equalTo(self.mainView);
|
|
make.size.mas_equalTo(CGSizeMake(24, 4));
|
|
make.top.mas_equalTo(self.collectionView.mas_bottom).mas_offset(10);
|
|
}];
|
|
[self.sliderView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(12, 4));
|
|
make.top.leading.bottom.mas_equalTo(self.slideBackView);
|
|
}];
|
|
} else {
|
|
[self.sliderView removeFromSuperview];
|
|
[self.slideBackView removeFromSuperview];
|
|
}
|
|
[self.collectionView reloadData];
|
|
}
|
|
|
|
- (UICollectionView *)collectionView{
|
|
if (!_collectionView) {
|
|
XPMineHeadFunctionItemLayout *layout = [[XPMineHeadFunctionItemLayout alloc] init];
|
|
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
|
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
|
|
_collectionView.dataSource = self;
|
|
_collectionView.delegate = self;
|
|
layout.minimumLineSpacing = 0;
|
|
layout.minimumInteritemSpacing = 10;
|
|
layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
|
|
_collectionView.backgroundColor = [DJDKMIMOMColor appCellBackgroundColor];
|
|
[_collectionView registerClass:[XPMineHeadItemCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPMineHeadItemCollectionViewCell class])];
|
|
_collectionView.showsHorizontalScrollIndicator = NO;
|
|
_collectionView.pagingEnabled = YES;
|
|
}
|
|
return _collectionView;
|
|
}
|
|
|
|
- (UIView *)sliderView {
|
|
if (!_sliderView) {
|
|
_sliderView = [[UIView alloc] init];
|
|
_sliderView.backgroundColor = [DJDKMIMOMColor appMainColor];
|
|
_sliderView.layer.cornerRadius = 2;
|
|
_sliderView.layer.masksToBounds = YES;
|
|
}
|
|
return _sliderView;
|
|
}
|
|
|
|
- (UIView *)slideBackView {
|
|
if (!_slideBackView) {
|
|
_slideBackView = [[UIView alloc] init];
|
|
_slideBackView.backgroundColor = UIColorRGBAlpha(0x000000, 0.1);
|
|
_slideBackView.layer.cornerRadius = 2;
|
|
_slideBackView.layer.masksToBounds = YES;
|
|
_slideBackView.clipsToBounds = YES;
|
|
}
|
|
return _slideBackView;
|
|
}
|
|
|
|
- (UIView *)mainView {
|
|
if (!_mainView) {
|
|
_mainView = [[UIView alloc] init];
|
|
_mainView.backgroundColor = [UIColor whiteColor];
|
|
_mainView.layer.cornerRadius = 8;
|
|
_mainView.layer.masksToBounds = YES;
|
|
}
|
|
return _mainView;
|
|
}
|
|
|
|
@end
|