// // YOUPAILZChatRoomEmojiAnimationWindow.m // VQU // // Created by CY on 2021/11/1. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAILZChatRoomEmojiAnimationWindow.h" #import "YOUPAILZChatRoomEmojiCell.h" #import "YOUPAIWZHorizontalPageFlowlayout.h" @interface YOUPAILZChatRoomEmojiAnimationWindow () @property (nonatomic,strong)NSArray *youpaipdataSource; @property (nonatomic,strong)UICollectionView *youpaipcollectionView; @property (nonatomic,strong)UIPageControl *youpaippageView; @end @implementation YOUPAILZChatRoomEmojiAnimationWindow - (void)viewDidLoad { [super viewDidLoad]; self.baseView.hidden = YES; [self youpaifinitUI]; [self youpaifrequestEmojiList]; } - (void)youpaifinitUI{ UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 243.0f + SafeHeight)]; bgV.backgroundColor = HexColorFromRGB(0x2A2935); [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:bgV size:CGSizeMake(20.0f, 20.0f)]; [self.view addSubview:bgV]; [bgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.offset(0.0f); make.height.offset(243.0f + SafeHeight); }]; UIView *footerV = [[UIView alloc] init]; [bgV addSubview:footerV]; [footerV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.offset(0.0f); make.bottom.offset(-SafeHeight); make.height.offset(47.0f); }]; UIButton *chatEmojiBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [chatEmojiBtn setTitle:@"聊天表情" forState:UIControlStateNormal]; [chatEmojiBtn setTitleColor:HexColorFromRGB(0x9F9DA5) forState:UIControlStateNormal]; chatEmojiBtn.titleLabel.font = LCFont(12.0f); [chatEmojiBtn addTarget:self action:@selector(youpaifchatEmojiBtnClick) forControlEvents:UIControlEventTouchUpInside]; [footerV addSubview:chatEmojiBtn]; [chatEmojiBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(0.0f); make.centerY.equalTo(footerV.mas_centerY); make.size.mas_offset(CGSizeMake(84.0f, 33.0f)); }]; UIButton *animationEmojiBtn = [UIButton buttonWithType:UIButtonTypeCustom]; animationEmojiBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [animationEmojiBtn setTitle:@"互动表情" forState:UIControlStateNormal]; [animationEmojiBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; animationEmojiBtn.titleLabel.font = LCFont(12.0f); animationEmojiBtn.userInteractionEnabled = NO; [footerV addSubview:animationEmojiBtn]; [animationEmojiBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(chatEmojiBtn.mas_right).offset(0.0f); make.centerY.equalTo(footerV.mas_centerY); make.size.mas_offset(CGSizeMake(84.0f, 33.0f)); }]; YOUPAIWZHorizontalPageFlowlayout *layout = [[YOUPAIWZHorizontalPageFlowlayout alloc] initWithRowCount:2 itemCountPerRow:4]; layout.youpaiprowSpacing = 13.0f; layout.itemSize = CGSizeMake(77.0f, 77.0f); layout.youpaipedgeInsets = UIEdgeInsetsMake(14.0f, 0.0f, 14.0f, 0.0f); layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; self.youpaipcollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, KScreenWidth, 243.0f-47.0f) collectionViewLayout:layout]; self.youpaipcollectionView.backgroundColor = [UIColor clearColor]; self.youpaipcollectionView.bounces = YES; self.youpaipcollectionView.pagingEnabled = YES; self.youpaipcollectionView.dataSource = self; self.youpaipcollectionView.delegate = self; self.youpaipcollectionView.showsHorizontalScrollIndicator=NO; self.youpaipcollectionView.showsVerticalScrollIndicator=NO; [self.youpaipcollectionView registerClass:[YOUPAILZChatRoomEmojiCell class] forCellWithReuseIdentifier:@"YOUPAILZChatRoomEmojiCell"]; [bgV addSubview:self.youpaipcollectionView]; UIPageControl *youpaippageView = [[UIPageControl alloc]initWithFrame:CGRectMake(0, self.youpaipcollectionView.mj_h - 8.0f, KScreenWidth, 8.0f)]; youpaippageView.currentPageIndicatorTintColor = [UIColor whiteColor]; youpaippageView.pageIndicatorTintColor = [[UIColor whiteColor] colorWithAlphaComponent:0.4f];; youpaippageView.userInteractionEnabled = NO; youpaippageView.hidesForSinglePage = YES; self.youpaippageView = youpaippageView; [bgV addSubview:youpaippageView]; } - (void)youpaifchatEmojiBtnClick{ [self dismissViewControllerAnimated:YES completion:^{ if (self.youpaipyoupaifchatEmojiBtnClickBlock != nil) { self.youpaipyoupaifchatEmojiBtnClickBlock(); } }]; } #pragma mark - UICollectionViewDataSource - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return self.youpaipdataSource.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { YOUPAILZChatRoomEmojiCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"YOUPAILZChatRoomEmojiCell" forIndexPath:indexPath]; [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.item]]; return cell; } -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ YOUPAILZChatRoomEmojiModel *model = self.youpaipdataSource[indexPath.item]; @weakify(self); [LCHttpHelper requestWithURLString:SendEmoji parameters:@{@"room_id":self.youpaipchatroomModel.youpaiproom_id,@"expression_id":model.youpaipid} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) {//成功 [self dismissViewControllerAnimated:YES completion:^{}]; } } failure:^(NSError *error) { }]; } -(void)scrollViewDidScroll:(UIScrollView *)scrollView{ // 当前的索引 NSInteger index = scrollView.contentOffset.x / self.youpaipcollectionView.mj_w; self.youpaippageView.currentPage = index; } - (void)youpaifrequestEmojiList{ @weakify(self); [LCHttpHelper requestWithURLString:GetExpressionCate parameters:@{@"expression_type":@"sign"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) {//成功 self.youpaipdataSource = [YOUPAILZChatRoomEmojiModel mj_objectArrayWithKeyValuesArray:[dict objectForKey:@"data"]]; NSInteger totalRecord = self.youpaipdataSource.count; NSInteger maxResult = 8; NSInteger totalPage = (totalRecord + maxResult - 1) / maxResult; self.youpaippageView.numberOfPages = totalPage; self.youpaippageView.currentPage = 0; [self.youpaipcollectionView reloadData]; } } failure:^(NSError *error) { }]; } @end