Files
yuyin_ios/SweetParty/主类/狸猫新增/相亲房/LMSendSpecialGiftView.m

167 lines
6.1 KiB
Mathematica
Raw Normal View History

2025-08-08 11:05:33 +08:00
//
// LMSendSpecialGiftView.m
// SweetParty
//
// Created by Xmac on 2024/8/29.
//
#import "LMSendSpecialGiftView.h"
#import "LMSpecialGiftModel.h"
#import "LMSendSpecialCollectionViewCell.h"
@interface LMSendSpecialGiftView ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UIView *mineView;
@property (weak, nonatomic) IBOutlet UIButton *confirmButton;
@property (weak, nonatomic) IBOutlet UICollectionView *giftItemView;
@property (nonatomic, strong) NSString *submitGid;
@property (nonatomic, strong) NSString *submitTagName;
@property (nonatomic, strong) NSMutableArray *dataArr;
@end
@implementation LMSendSpecialGiftView
- (void)awakeFromNib
{
[super awakeFromNib];
self.mineView.frame = CGRectMake(0, APPH, self.mineView.width, self.mineView.height);
self.mineView.backgroundColor = [UIColor bm_colorGradientChangeWithSize:CGSizeMake(APPW-30, 300) direction:(FXGradientChangeDirectionVertical) startColor:HEXCOLOR(0xDFFFF6) endColor:HEXCOLOR(0xFFFFFF)];
self.confirmButton.backgroundColor = [UIColor bm_colorGradientChangeWithSize:CGSizeMake(125, 44) direction:(FXGradientChangeDirectionHorizontal) startColor:mainLightColor endColor:mainDeepColor];
[self requestLoadSpecialGift];
UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
flow.itemSize = CGSizeMake(105, 126);
CGFloat left = (APPW-30-105*2-35)/2;
flow.sectionInset = UIEdgeInsetsMake(0, left, 0, left);
flow.minimumLineSpacing = 35;
flow.minimumInteritemSpacing = 35;
flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
self.giftItemView.collectionViewLayout = flow;
self.giftItemView.delegate = self;
self.giftItemView.dataSource = self;
[self.giftItemView registerNib:[UINib nibWithNibName:@"LMSendSpecialCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:LMSendSpecialCollectionViewCellID];
}
- (IBAction)confirmButtonClick:(UIButton *)sender {
if (self.submitGid.length == 0){
[HelpPageDefine showMessage:@"请选择礼物"];
return;
}
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setValue:self.rid forKey:@"rid"];
[dict setValue:self.close_uid forKey:@"close_uid"];
[dict setValue:self.submitGid forKey:@"gid"];
[dict setValue:@"1" forKey:@"num"];
[BJHttpTool BJ_XQ_reverse_send_giftParameters:dict success:^(id response) {
if ([self.submitTagName isEqualToString:@"灭亮灯"]){
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"特殊礼物灭亮灯" ofType:@"wav"];
int result = [self.viewModel.agoraKit playEffect:1 filePath:filePath loopCount:0 pitch:1 pan:0 gain:100 publish:YES];
if (result != 0) {
NSLog(@"音效播放失败");
}
}else if ([self.submitTagName isEqualToString:@"灭爆灯"]){
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"特殊礼物灭爆灯" ofType:@"mp3"];
int result = [self.viewModel.agoraKit playEffect:1 filePath:filePath loopCount:0 pitch:1 pan:0 gain:100 publish:YES];
if (result != 0) {
NSLog(@"音效播放失败");
}
}else if ([self.submitTagName isEqualToString:@"牵线"]){
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"特殊礼物普通牵线" ofType:@"mp3"];
int result = [self.viewModel.agoraKit playEffect:1 filePath:filePath loopCount:0 pitch:1 pan:0 gain:100 publish:YES];
if (result != 0) {
NSLog(@"音效播放失败");
}
}else if ([self.submitTagName isEqualToString:@"牵手"]){
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"特殊礼物牵手成功" ofType:@"mp3"];
int result = [self.viewModel.agoraKit playEffect:1 filePath:filePath loopCount:0 pitch:1 pan:0 gain:100 publish:YES];
if (result != 0) {
NSLog(@"音效播放失败");
}
}
[self sheetViewforViewClose];
} failure:^(NSError *error) {
}];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.dataArr.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
LMSendSpecialCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:LMSendSpecialCollectionViewCellID forIndexPath:indexPath];
if (self.dataArr.count > indexPath.row){
LMSpecialGiftModel *model = self.dataArr[indexPath.row];
cell.model = model;
}
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
LMSpecialGiftModel *model = self.dataArr[indexPath.row];
[self.dataArr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
LMSpecialGiftModel *nor = obj;
nor.isSelect = NO;
}];
model.isSelect = YES;
self.submitGid = model.gid;
self.submitTagName = model.tag_name;
[collectionView reloadData];
}
- (IBAction)cancelButtonClick:(UIButton *)sender {
[self sheetViewforViewClose];
}
- (void)sheetViewforViewAppear
{
//
[UIView animateWithDuration:0.3 animations:^{
self.mineView.frame = CGRectMake(0, APPH/2-330/2, self.mineView.width, self.mineView.height);
} completion:^(BOOL finished) {
}];
}
- (void)sheetViewforViewClose
{
self.backgroundColor = HEXCOLORA(0x000000, 0);
[UIView animateWithDuration:0.3 animations:^{
self.frame = CGRectMake(0, ScreenHeight, ScreenWidth, ScreenHeight);
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
- (void)requestLoadSpecialGift
{
//
[BJHttpTool BJ_XQ_appoint_giftParameters:@{@"type":@"2"} success:^(id response) {
self.dataArr = [LMSpecialGiftModel mj_objectArrayWithKeyValuesArray:response[@"data"]];
[self.giftItemView reloadData];
} failure:^(NSError *error) {
}];
}
@end