-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
PYFer
committed
Mar 8, 2023
1 parent
abe14bb
commit 37063f3
Showing
32 changed files
with
1,497 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...cenesDemo/PLVLiveCloudClassScene/Modules/Chatroom/View/PLVKeyboard/PLVLCIarEntranceView.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// PLVLCIarEntranceView.h | ||
// PolyvLiveScenesDemo | ||
// | ||
// Created by Dhan on 2023/2/21. | ||
// Copyright © 2023 PLV. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
#define PLVLCIarEntranceViewHeight (28.0) | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@class PLVLCIarEntranceView; | ||
|
||
@protocol PLVLCIarEntranceViewDelegate <NSObject> | ||
|
||
/// 打开互动应用模块 | ||
- (void)iarEntranceView_openInteractApp:(PLVLCIarEntranceView *)iarEntranceView eventName:(NSString *)eventName; | ||
|
||
@end | ||
|
||
@interface PLVLCIarEntranceView : UIView | ||
|
||
@property (nonatomic, weak) id<PLVLCIarEntranceViewDelegate> delegate; | ||
|
||
/// 更新按钮数据(根据传入的数据动态更新按钮) | ||
/// @param dataArray 前端传入的按钮数据 | ||
- (void)updateIarEntranceButtonDataArray:(NSArray *)dataArray; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
158 changes: 158 additions & 0 deletions
158
...cenesDemo/PLVLiveCloudClassScene/Modules/Chatroom/View/PLVKeyboard/PLVLCIarEntranceView.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
// | ||
// PLVLCIarEntranceView.m | ||
// PolyvLiveScenesDemo | ||
// | ||
// Created by Dhan on 2023/2/21. | ||
// Copyright © 2023 PLV. All rights reserved. | ||
// | ||
|
||
#import "PLVLCIarEntranceView.h" | ||
#import "PLVLCUtils.h" | ||
#import <SDWebImage/UIButton+WebCache.h> | ||
#import <PLVFoundationSDK/PLVFoundationSDK.h> | ||
|
||
static NSString *kIarEntranceViewCellIdentifier = @"kIarEntranceViewCellIdentifier"; | ||
static NSInteger kItemCountPerSection = 1; | ||
static CGFloat kCellButtonWidth = 68.0; | ||
static CGFloat kCellButtonHeight = 28.0; | ||
static CGFloat kCellLabelPadding = 4.0; | ||
|
||
@interface PLVLCLCIarEntranceCollectionViewCell : UICollectionViewCell | ||
|
||
@property (nonatomic, strong) UIButton *iarEntranceButton; | ||
|
||
@end | ||
|
||
@implementation PLVLCLCIarEntranceCollectionViewCell | ||
|
||
#pragma mark - Life Cycle | ||
|
||
- (instancetype)initWithFrame:(CGRect)frame { | ||
self = [super initWithFrame:frame]; | ||
if (self) { | ||
self.iarEntranceButton = [UIButton buttonWithType:UIButtonTypeCustom]; | ||
self.iarEntranceButton.frame = CGRectMake(0.0, 0.0, kCellButtonWidth, kCellButtonHeight); | ||
self.iarEntranceButton.titleLabel.font = [UIFont systemFontOfSize:12.0]; | ||
[self.iarEntranceButton setBackgroundColor:PLV_UIColorFromRGBA(@"#000000", 0.16)]; | ||
[self.iarEntranceButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; | ||
self.iarEntranceButton.imageView.contentMode = UIViewContentModeScaleAspectFit;; | ||
self.iarEntranceButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; | ||
[self.iarEntranceButton setTitleEdgeInsets:UIEdgeInsetsMake(0, kCellLabelPadding, 0, 0)]; | ||
[self.iarEntranceButton setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, kCellLabelPadding)]; | ||
self.iarEntranceButton.layer.masksToBounds = YES; | ||
self.iarEntranceButton.layer.cornerRadius = 12; | ||
|
||
[self.contentView addSubview:self.iarEntranceButton]; | ||
} | ||
return self; | ||
} | ||
|
||
@end | ||
|
||
@interface PLVLCIarEntranceView () <UICollectionViewDataSource> | ||
|
||
@property (nonatomic, strong) UICollectionView *collectionView; | ||
@property (nonatomic, strong) UICollectionViewFlowLayout *flowLayout; | ||
@property (nonatomic, strong) NSArray *dynamicDataArray; | ||
|
||
@end | ||
|
||
@implementation PLVLCIarEntranceView | ||
|
||
#pragma mark - Life Cycle | ||
|
||
- (instancetype)initWithFrame:(CGRect)frame { | ||
self = [super initWithFrame:frame]; | ||
if (self) { | ||
|
||
self.backgroundColor = [UIColor colorWithRed:0x1a/255.0 green:0x1b/255.0 blue:0x1f/255.0 alpha:1.0]; | ||
self.flowLayout = [[UICollectionViewFlowLayout alloc] init]; | ||
self.flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical; | ||
self.flowLayout.itemSize = CGSizeMake(kCellButtonWidth, kCellButtonHeight); | ||
self.flowLayout.minimumInteritemSpacing = 8.0; | ||
self.flowLayout.sectionInset = UIEdgeInsetsMake(0, 16, 0, 0); | ||
|
||
CGRect rect = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, kCellButtonHeight); | ||
self.collectionView = [[UICollectionView alloc] initWithFrame:rect collectionViewLayout:self.flowLayout]; | ||
self.collectionView.backgroundColor = [UIColor clearColor]; | ||
[self.collectionView registerClass:[PLVLCLCIarEntranceCollectionViewCell class] forCellWithReuseIdentifier:kIarEntranceViewCellIdentifier]; | ||
self.collectionView.dataSource = self; | ||
self.collectionView.showsHorizontalScrollIndicator = NO; | ||
self.collectionView.showsVerticalScrollIndicator = NO; | ||
[self addSubview:self.collectionView]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)layoutSubviews { | ||
[super layoutSubviews]; | ||
CGRect rect = CGRectMake(0, 0, self.frame.size.width, kCellButtonHeight); | ||
self.collectionView.frame = rect; | ||
} | ||
|
||
#pragma mark - [ Public Method ] | ||
|
||
- (void)updateIarEntranceButtonDataArray:(NSArray *)dataArray { | ||
NSMutableArray *showDataArray = [NSMutableArray array]; | ||
for (NSInteger index = 0; index < dataArray.count; index++) { | ||
NSDictionary *dict = dataArray[index]; | ||
if ([PLVFdUtil checkDictionaryUseable:dict]) { | ||
BOOL isShow = PLV_SafeBoolForDictKey(dict, @"isShow"); | ||
NSString *title = PLV_SafeStringForDictKey(dict, @"title"); | ||
if (isShow && [PLVFdUtil checkStringUseable:title] && [title isEqualToString:@"问卷"]) { | ||
[showDataArray addObject:dict]; | ||
} | ||
} | ||
} | ||
_dynamicDataArray = showDataArray; | ||
self.hidden = !showDataArray.count; | ||
[self.collectionView reloadData]; | ||
} | ||
|
||
#pragma mark - UICollectionView DataSource | ||
|
||
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView*)collectionView { | ||
return kItemCountPerSection; | ||
} | ||
|
||
- (NSInteger)collectionView:(UICollectionView*)collectionView numberOfItemsInSection:(NSInteger)section { | ||
return self.dynamicDataArray.count; | ||
} | ||
|
||
- (UICollectionViewCell *)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath { | ||
PLVLCLCIarEntranceCollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:kIarEntranceViewCellIdentifier forIndexPath:indexPath]; | ||
cell.iarEntranceButton.tag = indexPath.item; | ||
[self updateIarEntranceButton:cell.iarEntranceButton]; | ||
[cell.iarEntranceButton addTarget:self action:@selector(iarEntranceButtonAction:) forControlEvents:UIControlEventTouchUpInside]; | ||
|
||
return cell; | ||
} | ||
|
||
#pragma mark - Action | ||
|
||
- (void)iarEntranceButtonAction:(UIButton *)button { | ||
NSInteger index = button.tag; | ||
NSDictionary *dict = self.dynamicDataArray[index]; | ||
NSString *eventName = PLV_SafeStringForDictKey(dict, @"event"); | ||
if (self.delegate && [self.delegate respondsToSelector:@selector(iarEntranceView_openInteractApp:eventName:)]) { | ||
[self.delegate iarEntranceView_openInteractApp:self eventName:eventName]; | ||
} | ||
} | ||
|
||
#pragma mark - Private Method | ||
|
||
- (void)updateIarEntranceButton:(UIButton *)button { | ||
NSInteger index = button.tag; | ||
NSDictionary *dict = self.dynamicDataArray[index]; | ||
NSString *buttonTitle = PLV_SafeStringForDictKey(dict, @"title"); | ||
[button setTitle:buttonTitle forState:UIControlStateNormal]; | ||
[button setTitle:buttonTitle forState:UIControlStateSelected]; | ||
if (![PLVFdUtil checkStringUseable:buttonTitle]) { | ||
return; | ||
} else if ([buttonTitle isEqualToString:@"问卷"]) { | ||
[button setImage:[PLVLCUtils imageForChatroomResource:@"plvlc_iarentrance_questionnaire"] forState:UIControlStateNormal]; | ||
[button setImage:[PLVLCUtils imageForChatroomResource:@"plvlc_iarentrance_questionnaire"] forState:UIControlStateNormal]; | ||
} | ||
} | ||
|
||
@end |
Oops, something went wrong.