2023-09-05 11:45:21 +08:00
|
|
|
//
|
|
|
|
// XPNewHomeItemCell.m
|
|
|
|
// YuMi
|
|
|
|
//
|
|
|
|
// Created by duoban on 2023/9/5.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "XPNewHomeItemCell.h"
|
2024-06-21 01:37:38 +08:00
|
|
|
|
|
|
|
#import <SDCycleScrollView/SDCycleScrollView.h>
|
|
|
|
#import "PIHomeItemModel.h"
|
|
|
|
#import "HomeRankAvatarModel.h"
|
|
|
|
|
|
|
|
@interface XPRankAvatarsCell : UICollectionViewCell
|
|
|
|
@property (nonatomic, strong) NSArray<HomeRankAvatarModel*> *cellModel;
|
|
|
|
@property (nonatomic, strong) NetImageView *avatar_1;
|
|
|
|
@property (nonatomic, strong) NetImageView *avatar_2;
|
|
|
|
@property (nonatomic, strong) NetImageView *avatar_3;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation XPRankAvatarsCell
|
|
|
|
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
|
|
{
|
|
|
|
self = [super initWithFrame:frame];
|
|
|
|
if (self) {
|
|
|
|
[self setupCell];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setCellModel:(NSArray<HomeRankAvatarModel *> *)cellModel {
|
|
|
|
if ([cellModel xpSafeObjectAtIndex:0]) {
|
|
|
|
self.avatar_1.imageUrl = [[cellModel xpSafeObjectAtIndex:0] avatar];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([cellModel xpSafeObjectAtIndex:1]) {
|
|
|
|
self.avatar_2.imageUrl = [[cellModel xpSafeObjectAtIndex:1] avatar];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([cellModel xpSafeObjectAtIndex:2]) {
|
|
|
|
self.avatar_3.imageUrl = [[cellModel xpSafeObjectAtIndex:2] avatar];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setupCell {
|
|
|
|
// TODO:
|
|
|
|
UIImageView *headDress_1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"home_rank_Headdress_first"]];
|
|
|
|
UIImageView *headDress_2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"home_rank_Headdress_second"]];
|
|
|
|
UIImageView *headDress_3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"home_rank_Headdress_third"]];
|
|
|
|
headDress_1.contentMode = UIViewContentModeScaleAspectFit;
|
|
|
|
headDress_2.contentMode = UIViewContentModeScaleAspectFit;
|
|
|
|
headDress_3.contentMode = UIViewContentModeScaleAspectFit;
|
|
|
|
|
|
|
|
[self.contentView addSubview:headDress_3];
|
|
|
|
[self.contentView addSubview:headDress_2];
|
|
|
|
[self.contentView addSubview:headDress_1];
|
|
|
|
|
|
|
|
[headDress_1 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.centerX.mas_equalTo(self.contentView);
|
|
|
|
make.top.mas_equalTo(self.contentView).offset(9);
|
|
|
|
make.width.mas_equalTo(62);
|
|
|
|
make.height.mas_equalTo(48);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[headDress_2 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.mas_equalTo(self.contentView).offset(-15);
|
|
|
|
make.left.mas_equalTo(self.contentView).offset(21);
|
|
|
|
make.width.mas_equalTo(42);
|
|
|
|
make.height.mas_equalTo(33);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[headDress_3 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.mas_equalTo(self.contentView).offset(-15);
|
|
|
|
make.right.mas_equalTo(self.contentView).offset(-21);
|
|
|
|
make.width.mas_equalTo(42);
|
|
|
|
make.height.mas_equalTo(33);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.contentView insertSubview:self.avatar_1 belowSubview:headDress_1];
|
|
|
|
[self.contentView insertSubview:self.avatar_2 belowSubview:headDress_2];
|
|
|
|
[self.contentView insertSubview:self.avatar_3 belowSubview:headDress_3];
|
|
|
|
|
|
|
|
[self.avatar_1 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.mas_equalTo(headDress_1).offset(-1.5);
|
|
|
|
make.centerX.mas_equalTo(headDress_1);
|
|
|
|
make.width.height.mas_equalTo(34);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.avatar_2 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.mas_equalTo(headDress_2).offset(-1.5);
|
|
|
|
make.centerX.mas_equalTo(headDress_2);
|
|
|
|
make.width.height.mas_equalTo(22);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.avatar_3 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.mas_equalTo(headDress_3).offset(-1.5);
|
|
|
|
make.centerX.mas_equalTo(headDress_3);
|
|
|
|
make.width.height.mas_equalTo(22);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NetImageView *)avatar_1 {
|
|
|
|
if(!_avatar_1){
|
|
|
|
NetImageConfig *config = [[NetImageConfig alloc]init];
|
|
|
|
config.placeHolder = [UIImageConstant defaultBannerPlaceholder];
|
|
|
|
_avatar_1 = [[NetImageView alloc]initWithConfig:config];
|
|
|
|
_avatar_1.layer.cornerRadius = kGetScaleWidth(17);
|
|
|
|
_avatar_1.layer.masksToBounds = YES;
|
|
|
|
}
|
|
|
|
return _avatar_1;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NetImageView *)avatar_2 {
|
|
|
|
if(!_avatar_2){
|
|
|
|
NetImageConfig *config = [[NetImageConfig alloc]init];
|
|
|
|
config.placeHolder = [UIImageConstant defaultBannerPlaceholder];
|
|
|
|
_avatar_2 = [[NetImageView alloc]initWithConfig:config];
|
|
|
|
_avatar_2.layer.cornerRadius = kGetScaleWidth(11);
|
|
|
|
_avatar_2.layer.masksToBounds = YES;
|
|
|
|
}
|
|
|
|
return _avatar_2;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NetImageView *)avatar_3 {
|
|
|
|
if(!_avatar_3){
|
|
|
|
NetImageConfig *config = [[NetImageConfig alloc]init];
|
|
|
|
config.placeHolder = [UIImageConstant defaultBannerPlaceholder];
|
|
|
|
_avatar_3 = [[NetImageView alloc]initWithConfig:config];
|
|
|
|
_avatar_3.layer.cornerRadius = kGetScaleWidth(11);
|
|
|
|
_avatar_3.layer.masksToBounds = YES;
|
|
|
|
}
|
|
|
|
return _avatar_3;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface XPNewHomeItemCell () <SDCycleScrollViewDelegate>
|
2023-09-05 11:45:21 +08:00
|
|
|
///背景
|
|
|
|
@property(nonatomic,strong) NetImageView *bgImageView;
|
2024-06-21 01:37:38 +08:00
|
|
|
//@property (nonatomic, strong) UIImageView *rankImageView;
|
|
|
|
@property (nonatomic, strong) SDCycleScrollView *pi_BannerView;
|
|
|
|
@property (nonatomic, strong) UIScrollView *avatarScrollView;
|
|
|
|
@property (nonatomic, strong) NSArray *dataSource;
|
|
|
|
@property (nonatomic, strong) NSTimer *timer;
|
|
|
|
@property (nonatomic,strong) NSArray *avatarsList;
|
|
|
|
|
2023-09-05 11:45:21 +08:00
|
|
|
@end
|
|
|
|
@implementation XPNewHomeItemCell
|
|
|
|
-(instancetype)initWithFrame:(CGRect)frame{
|
|
|
|
self = [super initWithFrame:frame];
|
|
|
|
if(self){
|
|
|
|
[self installUI];
|
|
|
|
[self installConstraints];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
-(void)installUI{
|
|
|
|
[self.contentView addSubview:self.bgImageView];
|
|
|
|
}
|
|
|
|
-(void)installConstraints{
|
|
|
|
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.edges.equalTo(self.contentView);
|
|
|
|
}];
|
|
|
|
}
|
2024-06-21 01:37:38 +08:00
|
|
|
-(void)setItemModel:(PIHomeItemModel *)itmeModel{
|
|
|
|
_itemModel = itmeModel;
|
|
|
|
if ([itmeModel.ID isEqualToString:@"3"]) {
|
|
|
|
_bgImageView.image = [UIImage imageNamed:@"home_rank_Heads_bg"];
|
|
|
|
} else {
|
|
|
|
_bgImageView.layer.cornerRadius = kGetScaleWidth(12);
|
|
|
|
@kWeakify(self);
|
|
|
|
[_bgImageView loadImageWithUrl: _itemModel.icon completion:^(UIImage * _Nonnull image, NSURL * _Nonnull url) {
|
|
|
|
@kStrongify(self);
|
|
|
|
self.bgImageView.layer.cornerRadius = kGetScaleWidth(0);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setRankAvatarsModelArray:(NSArray<HomeRankAvatarModel *> *)rankAvatarsModelArray {
|
|
|
|
if (![self.itemModel.ID isEqualToString:@"3"]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (rankAvatarsModelArray.count>0) {
|
|
|
|
_rankAvatarsModelArray = rankAvatarsModelArray;
|
|
|
|
if (!self.pi_BannerView.superview) {
|
|
|
|
[self.contentView addSubview:self.pi_BannerView];
|
|
|
|
[self.pi_BannerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.edges.mas_equalTo(self);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
[self setupCycleScrollViews];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setupCycleScrollViews {
|
|
|
|
NSMutableArray * array = [NSMutableArray array];
|
|
|
|
[self.rankAvatarsModelArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
|
[array addObject:@"Fuck"];
|
|
|
|
}];
|
|
|
|
self.pi_BannerView.imageURLStringsGroup = array;
|
|
|
|
[self.pi_BannerView autoScroll];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - SDCycleScrollViewDelegate
|
|
|
|
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
|
|
|
|
{
|
|
|
|
if (_didTapRankArea) {
|
|
|
|
self.didTapRankArea();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (Class)customCollectionViewCellClassForCycleScrollView:(SDCycleScrollView *)view {
|
|
|
|
return XPRankAvatarsCell.class;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setupCustomCell:(UICollectionViewCell *)cell
|
|
|
|
forIndex:(NSInteger)index
|
|
|
|
cycleScrollView:(SDCycleScrollView *)view {
|
|
|
|
XPRankAvatarsCell *myCell = (XPRankAvatarsCell *)cell;
|
|
|
|
myCell.cellModel = [self.rankAvatarsModelArray xpSafeObjectAtIndex:index];
|
2023-09-05 11:45:21 +08:00
|
|
|
}
|
2024-06-21 01:37:38 +08:00
|
|
|
|
2023-09-05 11:45:21 +08:00
|
|
|
#pragma mark - 懒加载
|
|
|
|
- (NetImageView *)bgImageView{
|
|
|
|
if(!_bgImageView){
|
|
|
|
NetImageConfig *config = [[NetImageConfig alloc]init];
|
2024-06-21 01:37:38 +08:00
|
|
|
config.placeHolder = [UIImageConstant defaultBannerPlaceholder];
|
2023-09-05 11:45:21 +08:00
|
|
|
_bgImageView = [[NetImageView alloc]initWithConfig:config];
|
2023-10-17 18:30:14 +08:00
|
|
|
_bgImageView.layer.cornerRadius = kGetScaleWidth(12);
|
|
|
|
_bgImageView.layer.masksToBounds = YES;
|
2023-09-05 11:45:21 +08:00
|
|
|
}
|
|
|
|
return _bgImageView;
|
|
|
|
}
|
2024-06-21 01:37:38 +08:00
|
|
|
|
|
|
|
- (UIScrollView *)avatarScrollView {
|
|
|
|
if (!_avatarScrollView) {
|
|
|
|
_avatarScrollView = [[UIScrollView alloc] init];
|
|
|
|
}
|
|
|
|
return _avatarScrollView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (SDCycleScrollView *)pi_BannerView {
|
|
|
|
if (!_pi_BannerView) {
|
|
|
|
_pi_BannerView = [[SDCycleScrollView alloc] init];
|
|
|
|
_pi_BannerView.backgroundColor = [UIColor clearColor];
|
|
|
|
_pi_BannerView.layer.cornerRadius = 10;
|
|
|
|
_pi_BannerView.layer.masksToBounds = YES;
|
|
|
|
_pi_BannerView.delegate = self;
|
|
|
|
_pi_BannerView.showPageControl = NO;
|
2024-06-21 19:14:28 +08:00
|
|
|
_pi_BannerView.autoScrollTimeInterval = 5.0;
|
2024-06-21 16:14:36 +08:00
|
|
|
[_pi_BannerView disableScrollGesture];
|
2024-06-21 01:37:38 +08:00
|
|
|
_pi_BannerView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
|
|
|
|
_pi_BannerView.scrollDirection = UICollectionViewScrollDirectionVertical;
|
|
|
|
}
|
|
|
|
return _pi_BannerView;
|
|
|
|
}
|
|
|
|
|
2023-09-05 11:45:21 +08:00
|
|
|
@end
|
2024-06-21 01:37:38 +08:00
|
|
|
|