Files
yinmeng-ios-store/yinmeng-ios/DingDangApp/CodeClass/Room/View/PopView/RoomMoreManagementView.m
2023-12-07 10:50:21 +08:00

111 lines
4.5 KiB
Objective-C

//
// RoomMoreManagementView.m
// DingDangApp
//
// Created by apple on 2023/5/28.
//
#import "RoomMoreManagementView.h"
#import "RoomMoreManagementCell.h"
#import "RoomMoreManagementHeaderView.h"
#import "RoomSetModel.h"
@interface RoomMoreManagementView ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic,strong) UIImageView *bgImageView;
@end
@implementation RoomMoreManagementView
- (void)initView{
[self bgImageView];
[self collectionView];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return self.dataSource.count;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
NSArray *sectionArray = self.dataSource[section];
return sectionArray.count;
}
//header的size
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
return CGSizeMake(kWidth, KAdaptedHeight(44));
}
//通过设置SupplementaryViewOfKind 来设置头部或者底部的view
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
RoomMoreManagementHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"RoomMoreManagementHeaderView" forIndexPath:indexPath];
if(indexPath.section ==0){
headerView.titleLabel.text = @"房间设置";
}else{
headerView.titleLabel.text = @"更多操作";
}
return headerView;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
RoomMoreManagementCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"RoomMoreManagementCell" forIndexPath:indexPath];
NSArray *sectionArray = self.dataSource[indexPath.section];
RoomSetModel*model = sectionArray[indexPath.row];
cell.model = model;
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
NSArray *sectionArray = self.dataSource[indexPath.section];
RoomSetModel*model = sectionArray[indexPath.row];
[self dismiss];
if(self.backSelectSetModel){
self.backSelectSetModel(model);
}
}
- (UIImageView*)bgImageView{
if (!_bgImageView) {
_bgImageView = [[UIImageView alloc] init];
_bgImageView.image = KGetImage(@"room_33");
[self addSubview:_bgImageView];
[_bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self).insets(UIEdgeInsetsMake(0, 0, 0, 0));
}];
}
return _bgImageView;
}
- (WLBaseCollectionView *)collectionView{
if (!_collectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake((kWidth-32)/5, KAdaptedHeight(80));
layout.sectionInset = UIEdgeInsetsMake(0, 16,0, 16);
layout.minimumLineSpacing = 10;
layout.minimumInteritemSpacing = 0;
layout.headerReferenceSize = CGSizeZero;
_collectionView = [[WLBaseCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
[_collectionView registerClass:[RoomMoreManagementCell class] forCellWithReuseIdentifier:@"RoomMoreManagementCell"];
[_collectionView registerClass:[RoomMoreManagementHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"RoomMoreManagementHeaderView"];
_collectionView.delegate = self;
_collectionView.dataSource = self;
_collectionView.backgroundColor = Kclear_color;
if ([_collectionView respondsToSelector:@selector(setLayoutMargins:)]){
[_collectionView setLayoutMargins:UIEdgeInsetsZero];
}
_collectionView.translatesAutoresizingMaskIntoConstraints = NO;
if (@available(iOS 11.0, *)) {
[_collectionView adjustedContentInsetDidChange];
_collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
[self addSubview:_collectionView];
[_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self).insets(UIEdgeInsetsMake(0, 0, 0, 0));
}];
}
return _collectionView;
}
- (NSMutableArray*)dataSource{
if (!_dataSource) {
_dataSource = [[NSMutableArray alloc] init];
}
return _dataSource;
}
@end