123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- //
- // YMAccountBalanceRechargeItemView.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/28.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMAccountBalanceRechargeItemView.h"
- #import "YMAccountBalanceViewModel.h"
- #import "YMAccountBalanceRechargeItemCell.h"
- #import "CHTCollectionViewWaterfallLayout.h"
- @interface YMAccountBalanceRechargeItemView ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout,CHTCollectionViewDelegateWaterfallLayout>
- /// 账户余额VM
- @property (nonatomic, strong) YMAccountBalanceViewModel *viewModel;
- /// 充值项目提示标签
- @property (nonatomic, strong) UILabel *rechargeItemTipsLb;
- @property (nonatomic, strong) UIImageView *barnertView;
- /// 充值项目排版
- @property (nonatomic, strong) CHTCollectionViewWaterfallLayout *rechargeItemLayout;
- /// 充值项目容器列表
- @property (nonatomic, strong) UICollectionView *rechargeItemCollectionView;
- @end
- @implementation YMAccountBalanceRechargeItemView
- - (void)ym_setupViews{
- self.backgroundColor = UIColor.clearColor;
- [self addSubview:self.barnertView];
- [self addSubview:self.rechargeItemCollectionView];
- [self setNeedsUpdateConstraints];
- [self updateConstraintsIfNeeded];
- }
- - (void)updateConstraints{
-
- // [self.rechargeItemTipsLb mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.top.equalTo(self).offset(adapt(10));
- // make.left.equalTo(self).offset(adapt(10));
- // }];
-
- [self.barnertView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self).offset(adapt(16));
- make.left.equalTo(self);
- make.right.equalTo(self);
- //make.height.mas_equalTo(adapt(58));
- make.height.mas_equalTo(adapt(0.1));
- }];
- self.barnertView.hidden = YES;
-
- [self.rechargeItemCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.barnertView.mas_bottom).offset(adapt(16));
- make.left.equalTo(self);
- make.right.equalTo(self);
- make.bottom.equalTo(self).offset(adapt(-10));
- }];
-
- [super updateConstraints];
- }
- - (void)ym_bindViewModel:(YMAccountBalanceViewModel *)viewModel{
- if (!viewModel) {
- return;
- }
-
- _viewModel = viewModel;
-
- @weakify(self)
- [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
- @strongify(self)
- [self.rechargeItemCollectionView reloadData];
- [self.rechargeItemCollectionView layoutIfNeeded];
- //刷新高度
- CGFloat rechargeItemCollectionViewHeight = self.rechargeItemCollectionView.collectionViewLayout.collectionViewContentSize.height;
- [self.rechargeItemCollectionView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(rechargeItemCollectionViewHeight);
- }];
-
- ///默认选中
- if (self.viewModel.rechargeItemDataArray.count > 0) {
- NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
- [self.rechargeItemCollectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
- [self collectionView:self.rechargeItemCollectionView didSelectItemAtIndexPath:indexPath];
- }
- }];
- }
- #pragma mark - UICollectionViewDataSource
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return self.viewModel.rechargeItemDataArray.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- YMAccountBalanceRechargeItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([YMAccountBalanceRechargeItemCell class]) forIndexPath:indexPath];
- [cell ym_bindViewModel:self.viewModel.rechargeItemDataArray[indexPath.item]];
- return cell;
- }
- - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
- UICollectionReusableView *reusableView = nil;
- reusableView.backgroundColor = [UIColor clearColor];
- return reusableView;
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
- return CGSizeZero;
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
- return CGSizeZero;
- }
- #pragma mark - UICollectionViewDelegate
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- [self.viewModel.selectedRechargeItemSubject sendNext:@(indexPath.item)];
- }
- #pragma mark - CHTCollectionViewDelegateWaterfallLayout
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- return CGSizeMake(adapt(110), adapt(82));
- }
- - (UILabel *)rechargeItemTipsLb{
- if (!_rechargeItemTipsLb) {
- _rechargeItemTipsLb = [[UILabel alloc]init];
- _rechargeItemTipsLb.font = LCFont(11);
- _rechargeItemTipsLb.textColor = HexColorFromRGB(0x000000);
- _rechargeItemTipsLb.textAlignment = NSTextAlignmentLeft;
- _rechargeItemTipsLb.text = @"请选择充值金币:";
- }
- return _rechargeItemTipsLb;
- }
- - (UIImageView *)barnertView{
- if (!_barnertView) {
- _barnertView = [[UIImageView alloc]init];
- _barnertView.image = ImageByName(@"ym_account_barner_bg");
- _barnertView.userInteractionEnabled = true;
- WS(weakSelf)
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
- [_barnertView addGestureRecognizer:tap];
- [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
- [weakSelf.viewModel clickRechargeImageView];
- }];
- }
- return _barnertView;
- }
- - (CHTCollectionViewWaterfallLayout *)rechargeItemLayout{
- if (!_rechargeItemLayout) {
- _rechargeItemLayout = [[CHTCollectionViewWaterfallLayout alloc] init];
- _rechargeItemLayout.columnCount = 3;
- _rechargeItemLayout.minimumColumnSpacing = adapt(10);
- _rechargeItemLayout.minimumInteritemSpacing = adapt(10);
- }
- return _rechargeItemLayout;
- }
- - (UICollectionView *)rechargeItemCollectionView{
- if (!_rechargeItemCollectionView) {
- _rechargeItemCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:self.rechargeItemLayout];
- _rechargeItemCollectionView.delegate = self;
- _rechargeItemCollectionView.dataSource = self;
- _rechargeItemCollectionView.showsVerticalScrollIndicator = NO;
- _rechargeItemCollectionView.showsHorizontalScrollIndicator = NO;
- _rechargeItemCollectionView.backgroundColor = UIColor.clearColor;
- [_rechargeItemCollectionView registerClass:[YMAccountBalanceRechargeItemCell class] forCellWithReuseIdentifier:NSStringFromClass([YMAccountBalanceRechargeItemCell class])];
- }
- return _rechargeItemCollectionView;
- }
- @end
|