Files
peko-ios/YuMi/Modules/YMRoom/View/ActivityContainerView/PIRoomActivityChoosePlayView.m
2024-02-23 18:35:35 +08:00

130 lines
4.9 KiB
Objective-C

//
// PIRoomActivityChoosePlayView.m
// YuMi
//
// Created by duoban on 2024/2/20.
//
#import "PIRoomActivityChoosePlayView.h"
#import "PIRoomActivityChoosePlayCell.h"
#import "ActivityInfoModel.h"
@interface PIRoomActivityChoosePlayView ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property(nonatomic,strong) UIButton *clickBtn;
@property(nonatomic,strong) UICollectionView *collectionView;
@property(nonatomic,strong) UIImageView *bgImageView;
@property (nonatomic, strong) UIVisualEffectView *effectView;
@end
@implementation PIRoomActivityChoosePlayView
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
[self installUI];
[self installConstraints];
}
return self;
}
-(void)installUI{
self.backgroundColor = [UIColor clearColor];
[self addSubview:self.clickBtn];
[self addSubview:self.bgImageView];
[self.bgImageView addSubview:self.effectView];
[self.bgImageView addSubview:self.collectionView];
}
-(void)installConstraints{
[self.clickBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(14);
make.leading.equalTo(self);
make.centerY.equalTo(self);
}];
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(-6);
make.top.bottom.equalTo(self);
make.width.mas_equalTo(180);
}];
[self.effectView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.bgImageView);
}];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.bgImageView);
}];
}
-(void)setPlayList:(NSMutableArray *)playList{
_playList = playList;
[self.collectionView reloadData];
}
#pragma mark - UICollectionViewDelegate,UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return self.playList.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
PIRoomActivityChoosePlayCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([PIRoomActivityChoosePlayCell class]) forIndexPath:indexPath];
ActivityInfoModel *model = [self.playList safeObjectAtIndex1:indexPath.row];
cell.imageUrl = model.icon;
return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
ActivityInfoModel *model = [self.playList safeObjectAtIndex1:indexPath.row];
if(self.delegate && [self.delegate respondsToSelector:@selector(choosePlayTypeWithView:model:)]){
[self.delegate choosePlayTypeWithView:self model:model];
}
}
-(void)clickBtnAction{
if(self.delegate && [self.delegate respondsToSelector:@selector(hiddenViewActionWithView:)]){
[self.delegate hiddenViewActionWithView:self];
}
}
#pragma mark - 懒加载
- (UICollectionView *)collectionView{
if(!_collectionView){
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.minimumLineSpacing = 8;
layout.minimumInteritemSpacing = 8;
layout.itemSize = CGSizeMake(48, 48);
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.dataSource = self;
_collectionView.delegate = self;
_collectionView.backgroundColor = [UIColor clearColor];
[_collectionView registerClass:[ PIRoomActivityChoosePlayCell class] forCellWithReuseIdentifier:NSStringFromClass([ PIRoomActivityChoosePlayCell class])];
}
return _collectionView;
}
- (UIButton *)clickBtn{
if(!_clickBtn){
_clickBtn = [UIButton new];
[_clickBtn setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
[_clickBtn setImage:kImage(@"pi_room_activity_choose_play_arrow") forState:UIControlStateNormal];
[_clickBtn addTarget:self action:@selector(clickBtnAction) forControlEvents:UIControlEventTouchUpInside];
}
return _clickBtn;
}
- (UIImageView *)bgImageView{
if(!_bgImageView){
_bgImageView = [UIImageView new];
_bgImageView.layer.cornerRadius = 12;
_bgImageView.layer.masksToBounds = YES;
_bgImageView.layer.borderColor = [UIColor colorWithWhite:1 alpha:0.8].CGColor;
_bgImageView.layer.borderWidth = 1;
_bgImageView.userInteractionEnabled = YES;
}
return _bgImageView;
}
- (UIVisualEffectView *)effectView {
if (!_effectView) {
UIBlurEffect *beffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
_effectView = [[UIVisualEffectView alloc] initWithEffect:beffect];
_effectView.alpha = 0.8;
}
return _effectView;
}
@end