YBGiftView.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. //
  2. // YBGiftView.m
  3. // YBVideo
  4. //
  5. // Created by YB007 on 2019/8/19.
  6. // Copyright © 2019 cat. All rights reserved.
  7. //
  8. #import "YBGiftView.h"
  9. #import "YBGiftCell.h"
  10. #import "YBGiftModel.h"
  11. #import "YBRechargeVC.h"
  12. @interface CollectionCellWhite : UICollectionViewCell
  13. @end
  14. @implementation CollectionCellWhite
  15. - (instancetype)initWithFrame:(CGRect)frame andPlayDic:(NSDictionary *)zhuboDic{
  16. self = [super initWithFrame:frame];
  17. if (self) {
  18. self.backgroundColor = [UIColor clearColor];
  19. }
  20. return self;
  21. }
  22. @end
  23. @interface YBGiftView()<UIGestureRecognizerDelegate,UICollectionViewDelegate,UICollectionViewDataSource> {
  24. NSArray *_dataArray; //礼物+金币
  25. NSArray *_giftList; //礼物
  26. NSString *_coinNum; //金币数量
  27. NSInteger _pageCount;
  28. NSMutableArray *_selArray;
  29. BOOL isRight;
  30. NSTimer *_continueTimer;
  31. int _intervalTime;
  32. CGFloat _collectionHeght;
  33. int _perRowNums;
  34. int _rowNums;
  35. NSString *_methodUrl;
  36. }
  37. @property(nonatomic,strong)UILabel *coinL;
  38. @property(nonatomic,strong)YBGiftModel *selModel;
  39. @property(nonatomic,strong)NSArray *giftModels;
  40. @property(nonatomic,strong)CABasicAnimation *animation;
  41. /**
  42. * 新加礼物组功能: 父视图为 _bottomMixBg
  43. */
  44. @property(nonatomic,strong)UIImageView *multipleIV; //礼物组
  45. @property(nonatomic,strong)NSArray *mutipleGiftA;
  46. @property(nonatomic,strong)UIView *multipleGiftCountBg; //礼物组数量选择背景
  47. @property(nonatomic,strong)UIButton *multipleCountBtn; //礼物组数量选择按钮
  48. @property(nonatomic,strong)UIButton *multipleSendBtn; //礼物组赠送按钮
  49. @property(nonatomic,assign)ShowTypeOfGift typeOfGift;
  50. @end
  51. @implementation YBGiftView
  52. - (void)awakeFromNib {
  53. [super awakeFromNib];
  54. //添加背包礼物,_giftTitleL被YBGiftPage中的tabbar代替
  55. _giftTitleL.text = YZMsg(@"打赏礼物");
  56. _giftTitleL.hidden = YES;
  57. _sendBtn.hidden = NO;
  58. [_sendBtn setTitle:YZMsg(@"赠送") forState:0];
  59. _continueSendBtn.hidden = YES;
  60. _continueSendBtn.titleLabel.numberOfLines = 0;
  61. [_continueSendBtn setBackgroundImage:[UIImage imageNamed:@"gift_continus"] forState:0];
  62. [_sendBtn setBackgroundImage:[PublicObj getImgWithColor:RGB_COLOR(@"#dcdcdc", 1)] forState:0];
  63. [_sendBtn setBackgroundImage:[PublicObj getImgWithColor:Pink_Cor] forState:UIControlStateSelected];
  64. _perRowNums = 5;
  65. _rowNums = 2;
  66. _pageCount = 0;
  67. _intervalTime = 5;
  68. _selArray = [NSMutableArray array];
  69. //礼物组
  70. [_bottomMixBg addSubview:self.multipleIV];
  71. [_bottomMixBg bringSubviewToFront:self.continueSendBtn];
  72. [_multipleIV mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.centerY.equalTo(_bottomMixBg);
  74. make.right.equalTo(_bottomMixBg).offset(-15);
  75. make.width.mas_equalTo(94);
  76. make.height.mas_equalTo(26);
  77. }];
  78. _mutipleGiftA = @[@"1314",@"520",@"100",@"88",@"66",@"10",@"1"];
  79. }
  80. - (NSArray *)giftModels {
  81. // if (!_giftModels) {
  82. NSMutableArray *m_array = [NSMutableArray array];
  83. for (NSDictionary*dic in _giftList) {
  84. YBGiftModel *model = [YBGiftModel modelWithDic:dic];
  85. [m_array addObject:model];
  86. // }
  87. _giftModels = [m_array copy];
  88. }
  89. return _giftModels;
  90. }
  91. +(instancetype)showTypeOfGiftViewComplete:(RewardGiftBlock)complete {
  92. YBGiftView *gV = [[[NSBundle mainBundle]loadNibNamed:@"YBGiftView" owner:nil options:nil]objectAtIndex:0];
  93. if (complete) {
  94. gV.giftEvent = ^(int eventCode,NSDictionary *giftDic) {
  95. complete(eventCode,giftDic);
  96. };
  97. }
  98. [gV setUpView];
  99. return gV;
  100. }
  101. -(void)setUpView{
  102. CGFloat subViewHeight = (_window_width*322/375+ShowDiff);
  103. if (IS_IPHONE_5) {
  104. subViewHeight = (_window_width*322/375+ShowDiff)+15;
  105. }
  106. self.frame = CGRectMake(0, _window_height-subViewHeight, _window_width, subViewHeight);
  107. NSLog(@"=:%@",self.bgView);
  108. _bgViewHeight.constant = subViewHeight;
  109. _bgView.backgroundColor = UIColor.clearColor;
  110. _collectionHeght = _window_width*220/375;
  111. [_bgView layoutIfNeeded];
  112. //
  113. _GiftLayout.itemCountPerRow = _perRowNums;
  114. _GiftLayout.rowCount = _rowNums;
  115. _GiftLayout.minimumLineSpacing = 0;
  116. _GiftLayout.minimumInteritemSpacing = 0;
  117. _GiftLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  118. _giftCollectionView.delegate = self;
  119. _giftCollectionView.dataSource = self;
  120. [_giftCollectionView registerNib:[UINib nibWithNibName:@"YBGiftCell" bundle:nil] forCellWithReuseIdentifier:@"YBGiftCell"];
  121. [_giftCollectionView registerClass:[CollectionCellWhite class] forCellWithReuseIdentifier:@"CellWhite"];
  122. }
  123. -(void)requestGiftData:(NSString *)giftUrl {
  124. _methodUrl = giftUrl;
  125. _typeOfGift = ShowTypeOfGift_Normal;
  126. if ([giftUrl containsString:@"Backpack.getBackpack"]) {
  127. _typeOfGift = ShowTypeOfGift_Bag;
  128. }
  129. [MBProgressHUD showMessage:@""];
  130. [self pullData];
  131. }
  132. -(void)pullData {
  133. [YBNetworking postWithUrl:_methodUrl Dic:nil Suc:^(int code, id info, NSString *msg) {
  134. [MBProgressHUD hideHUD];
  135. if (code == 0) {
  136. _dataArray = [NSArray arrayWithArray:info];
  137. NSDictionary *dataDic = @{};
  138. if ([[_dataArray firstObject] isKindOfClass:[NSDictionary class]]) {
  139. dataDic = [_dataArray firstObject];
  140. }
  141. if (!_selArray) {
  142. _selArray = [NSMutableArray array];
  143. }
  144. if ([[dataDic valueForKey:@"giftlist"]isKindOfClass:[NSArray class]]) {
  145. _giftList = [NSArray arrayWithArray:[dataDic valueForKey:@"giftlist"]];
  146. }
  147. _coinNum = minstr([dataDic valueForKey:@"coin"]);
  148. _coinL.text = minstr(_coinNum);
  149. [Config saveUserCoin:_coinNum];
  150. _pageCount = _giftList.count;
  151. while (_pageCount % 8 !=0) {
  152. ++_pageCount;
  153. }
  154. for (int i = 0 ; i<_giftList.count; i++) {
  155. [_selArray addObject:@"0"];
  156. }
  157. if (_giftList.count > 0) {
  158. _giftPage.hidden = NO;
  159. if ((int)_giftList.count % (_perRowNums*_rowNums) == 0) {
  160. _giftPage.numberOfPages = _giftList.count/(_perRowNums*_rowNums);
  161. }
  162. else{
  163. _giftPage.numberOfPages = _giftList.count/(_perRowNums*_rowNums) + 1;
  164. }
  165. }else {
  166. _giftPage.hidden = YES;
  167. }
  168. [_giftCollectionView reloadData];
  169. if (_giftList.count <= 0) {
  170. [PublicView showTextNoData:_giftCollectionView text1:@"" text2:YZMsg(@"暂无数据") centerY:0.6];
  171. }else {
  172. [PublicView hiddenTextNoData:_giftCollectionView];
  173. }
  174. if (_typeOfGift == ShowTypeOfGift_Normal) {
  175. //金币列表
  176. [self setCoinListUI];
  177. }
  178. }else {
  179. [MBProgressHUD showPop:msg];
  180. }
  181. } Fail:^(id fail) {
  182. [MBProgressHUD hideHUD];
  183. }];
  184. }
  185. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  186. return _pageCount;
  187. }
  188. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  189. return 1;
  190. }
  191. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  192. if (indexPath.item >= self.giftModels.count) {
  193. UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CellWhite" forIndexPath:indexPath];
  194. return cell;
  195. } else {
  196. YBGiftCell *cell = (YBGiftCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"YBGiftCell" forIndexPath:indexPath];
  197. YBGiftModel *model = self.giftModels[indexPath.item];
  198. [collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
  199. cell.typeOfGift = _typeOfGift;
  200. cell.model = model;
  201. NSString *selFlag = [NSString stringWithFormat:@"%@",_selArray[indexPath.item]];
  202. if ([selFlag isEqual:@"1"]) {
  203. cell.flagIV.hidden = NO;
  204. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  205. [cell.iconIV.layer addAnimation:self.animation forKey:nil];
  206. });
  207. }
  208. else{
  209. cell.flagIV.hidden = YES;
  210. [cell.iconIV.layer removeAllAnimations];
  211. }
  212. return cell;
  213. }
  214. }
  215. - (void)addAnimation:(NSIndexPath *)indexpath{
  216. for (YBGiftCell *cell in _giftCollectionView.visibleCells) {
  217. if ([[_giftCollectionView indexPathForCell:cell] isEqual:indexpath]) {
  218. [cell.iconIV.layer addAnimation:self.animation forKey:nil];
  219. }else{
  220. [cell.iconIV.layer removeAllAnimations];
  221. }
  222. }
  223. }
  224. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;{
  225. [_giftCollectionView reloadData];
  226. }
  227. -(CABasicAnimation *)animation{
  228. if (!_animation) {
  229. _animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
  230. _animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  231. _animation.duration = 0.88;
  232. _animation.repeatCount = 9999999;
  233. _animation.autoreverses = YES;
  234. _animation.fromValue = [NSNumber numberWithFloat:1];
  235. _animation.toValue = [NSNumber numberWithFloat:0.8];
  236. }
  237. return _animation;
  238. }
  239. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  240. if (indexPath.item>=self.giftModels.count) {
  241. return;
  242. }
  243. if (self.giftViewSwitchEvent) {
  244. self.giftViewSwitchEvent(self);
  245. }
  246. _sendBtn.selected = YES;
  247. [_selArray removeAllObjects];
  248. for (int i=0; i<self.giftModels.count; i++) {
  249. [_selArray addObject:@"0"];
  250. }
  251. [_selArray replaceObjectAtIndex:indexPath.item withObject:@"1"];
  252. _selModel = self.giftModels[indexPath.item];
  253. [self destroyTimer];
  254. _continueSendBtn.hidden = YES;
  255. //判断手绘礼物
  256. [self judesSelIsPaintedGift];
  257. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  258. [_giftCollectionView reloadData];
  259. });
  260. }
  261. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  262. return CGSizeMake(_window_width/_perRowNums,(_collectionHeght-2)/_rowNums);
  263. }
  264. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  265. return UIEdgeInsetsMake(0,0,0,0);
  266. }
  267. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  268. return 0;
  269. }
  270. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  271. return 0;
  272. }
  273. - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
  274. if(velocity.x>0){
  275. NSLog(@"右滑");
  276. isRight = YES;
  277. }else{
  278. NSLog(@"左滑");
  279. isRight = NO;
  280. }
  281. NSLog(@"scrollViewWillEndDragging");
  282. if (isRight) {
  283. _giftPage.currentPage+=1;
  284. }
  285. else{
  286. _giftPage.currentPage-=1;
  287. }
  288. }
  289. -(void)cancelGiftSel {
  290. if (_selArray.count <= 0 || !_selModel) {
  291. return;
  292. }
  293. [_selArray removeAllObjects];
  294. for (int i=0; i<self.giftModels.count; i++) {
  295. [_selArray addObject:@"0"];
  296. }
  297. _selModel = nil;
  298. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  299. [_giftCollectionView reloadData];
  300. });
  301. [self destroyTimer];
  302. _continueSendBtn.hidden = YES;
  303. _sendBtn.selected = NO;
  304. _paintedRegion.showPainted = NO;
  305. _sendBtn.hidden = NO;
  306. _multipleIV.hidden = YES;
  307. }
  308. - (void)judesSelIsPaintedGift {
  309. _coinNum = minstr([Config getUserCoin]);
  310. _coinL.text = _coinNum;
  311. if (!_selModel) {
  312. return;
  313. }
  314. //0-普通 1-豪华 2-涂鸦
  315. if ([_selModel.typeStr isEqual:@"2"]) {
  316. _sendBtn.hidden = NO;
  317. _multipleIV.hidden = YES;
  318. _paintedRegion.showPainted = YES;
  319. _paintedRegion.giftNameStr = _selModel.giftNameStr;
  320. _paintedRegion.giftPathStr = _selModel.giftIconStr;
  321. }else if ([_selModel.typeStr isEqual:@"1"]) {
  322. _sendBtn.hidden = NO;
  323. _multipleIV.hidden = YES;
  324. _paintedRegion.showPainted = NO;
  325. }else{
  326. _sendBtn.hidden = YES;
  327. _multipleIV.hidden = NO;
  328. _paintedRegion.showPainted = NO;
  329. }
  330. }
  331. -(void)dismiss {
  332. if (self.giftEvent) {
  333. self.giftEvent(-1, @{});
  334. }
  335. [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  336. [self removeFromSuperview];
  337. [self destroyTimer];
  338. }
  339. - (IBAction)clickCloseBtn:(UIButton *)sender {
  340. [self dismiss];
  341. }
  342. - (IBAction)clickSendBtn:(UIButton *)sender {
  343. if (_selModel && [_selModel.typeStr isEqual:@"2"] && [_paintedRegion getPaintedPointArray].count < PaintedMinNum) {
  344. NSString *msg = [NSString stringWithFormat:@"%@%d%@",YZMsg(@"最少绘制"),PaintedMinNum,YZMsg(@"个礼物")];
  345. [MBProgressHUD showPop:msg];
  346. return;
  347. }
  348. if (_sendType == SendGiftType_Video) {
  349. [self sendVideoGift];
  350. }else {
  351. [self sendLiveGift];
  352. }
  353. }
  354. - (IBAction)clickContinueSendBtn:(UIButton *)sender {
  355. if (_sendType == SendGiftType_Video) {
  356. [self sendVideoGift];
  357. }else {
  358. [self sendLiveGift];
  359. }
  360. }
  361. #pragma mark - 视频送礼物开始
  362. -(void)sendVideoGift {
  363. if(!_selModel){
  364. return;
  365. }
  366. if ([PublicObj checkNull:_receiveID]) {
  367. [MBProgressHUD showPop:YZMsg(@"缺少礼物信息")];
  368. return;
  369. }
  370. NSString *lianfa = @"y";
  371. NSLog(@"发送了%@",_selModel.giftNameStr);
  372. NSString *sendCount;
  373. //0-普通 1-豪华 2-涂鸦
  374. if ([_selModel.typeStr isEqual:@"2"]) {
  375. lianfa = @"n";
  376. _continueSendBtn.hidden = YES;
  377. _multipleIV.hidden = YES;
  378. _sendBtn.hidden = NO;
  379. sendCount = [NSString stringWithFormat:@"%lu",(unsigned long)[_paintedRegion getPaintedPointArray].count];
  380. }else if ([_selModel.typeStr isEqual:@"1"]) {
  381. lianfa = @"n";
  382. _continueSendBtn.hidden = YES;
  383. _multipleIV.hidden = YES;
  384. _sendBtn.hidden = NO;
  385. sendCount = @"1";
  386. }else{
  387. /*
  388. _continueSendBtn.hidden = NO;
  389. _multipleIV.hidden = YES;
  390. _sendBtn.hidden = YES;
  391. _intervalTime = 5;
  392. [_continueSendBtn setTitle:[NSString stringWithFormat:@"%@\n %ds",YZMsg(@"连发"),_intervalTime] forState:UIControlStateNormal];
  393. if(_continueTimer == nil){
  394. _continueTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(continueSendInterval) userInfo:nil repeats:YES];
  395. }
  396. */
  397. sendCount = minstr(_multipleCountBtn.titleLabel.text);
  398. }
  399. NSDictionary *giftDic = @{
  400. @"videoid":minstr(_receiveID),
  401. @"giftid":_selModel.idStr,
  402. @"giftcount":minstr(sendCount),
  403. @"ispack":_typeOfGift == ShowTypeOfGift_Bag ?@"1":@"0",
  404. };
  405. if ([lianfa isEqual:@"n"]) {
  406. [MBProgressHUD showMessage:@""];
  407. }
  408. YBWeakSelf;
  409. [YBNetworking postWithUrl:@"Video.videoSendGift" Dic:giftDic Suc:^(int code, id info, NSString *msg) {
  410. [MBProgressHUD hideHUD];
  411. if (code == 0) {
  412. if([_selModel.typeStr isEqual:@"0"]){
  413. [weakSelf startContinueSendTimer];
  414. }
  415. NSDictionary *infoDic = [info firstObject];
  416. _coinNum = minstr([infoDic valueForKey:@"coin"]);
  417. _coinL.text = _coinNum;
  418. [Config saveUserCoin:_coinNum];
  419. NSDictionary *giftInfoDic = [infoDic valueForKey:@"giftinfo"];
  420. NSMutableDictionary *dic = @{
  421. @"avatar":[Config getUserAvatar],
  422. @"nickname":[Config getOwnNicename],
  423. @"uid":[Config getOwnID],
  424. @"paintedPath":[_paintedRegion getPaintedPointArray],
  425. @"paintedWidth":@([_paintedRegion getPaintedRegion].width),
  426. @"paintedHeight":@([_paintedRegion getPaintedRegion].height),
  427. }.mutableCopy;
  428. [dic addEntriesFromDictionary:giftInfoDic];
  429. if ([_selModel.typeStr isEqual:@"2"]) {
  430. [weakSelf dismiss];
  431. }
  432. if (weakSelf.giftEvent) {
  433. weakSelf.giftEvent(0, dic);
  434. }
  435. if (_typeOfGift == ShowTypeOfGift_Bag) {
  436. [weakSelf pullData];
  437. }
  438. }else{
  439. [MBProgressHUD showError:msg];
  440. }
  441. } Fail:^(id fail) {
  442. [MBProgressHUD hideHUD];
  443. }];
  444. }
  445. #pragma mark - 视频送礼物结束
  446. #pragma mark - 直播送礼物开始
  447. -(void)sendLiveGift {
  448. if(!_selModel){
  449. return;
  450. }
  451. if ([PublicObj checkNull:_receiveID] || [PublicObj checkNull:_receiveStream]) {
  452. [MBProgressHUD showPop:YZMsg(@"缺少礼物信息")];
  453. return;
  454. }
  455. NSString *lianfa = @"y";
  456. NSLog(@"发送了%@",_selModel.giftNameStr);
  457. NSString *sendCount;
  458. //0-普通 1-豪华 2-涂鸦
  459. if ([_selModel.typeStr isEqual:@"2"]) {
  460. lianfa = @"n";
  461. _continueSendBtn.hidden = YES;
  462. _multipleIV.hidden = YES;
  463. _sendBtn.hidden = NO;
  464. sendCount = [NSString stringWithFormat:@"%lu",(unsigned long)[_paintedRegion getPaintedPointArray].count];
  465. }else if ([_selModel.typeStr isEqual:@"1"]) {
  466. lianfa = @"n";
  467. _continueSendBtn.hidden = YES;
  468. _multipleIV.hidden = YES;
  469. _sendBtn.hidden = NO;
  470. sendCount = @"1";
  471. }else{
  472. /*
  473. _continueSendBtn.hidden = NO;
  474. _multipleIV.hidden = YES;
  475. _sendBtn.hidden = YES;
  476. _intervalTime = 5;
  477. [_continueSendBtn setTitle:[NSString stringWithFormat:@"%@\n %ds",YZMsg(@"连发"),_intervalTime] forState:UIControlStateNormal];
  478. if(_continueTimer == nil){
  479. _continueTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(continueSendInterval) userInfo:nil repeats:YES];
  480. }
  481. */
  482. sendCount = minstr(_multipleCountBtn.titleLabel.text);
  483. }
  484. NSDictionary *giftDic = @{
  485. @"liveuid":minstr(_receiveID),
  486. @"stream":minstr(_receiveStream),
  487. @"giftid":_selModel.idStr,
  488. @"giftcount":minstr(sendCount),
  489. @"ispack":_typeOfGift == ShowTypeOfGift_Bag ?@"1":@"0",
  490. };
  491. if ([lianfa isEqual:@"n"]) {
  492. [MBProgressHUD showMessage:@""];
  493. }
  494. YBWeakSelf;
  495. [YBNetworking postWithUrl:@"Live.sendGift" Dic:giftDic Suc:^(int code, id info, NSString *msg) {
  496. [MBProgressHUD hideHUD];
  497. if (code == 0) {
  498. if([_selModel.typeStr isEqual:@"0"]){
  499. [weakSelf startContinueSendTimer];
  500. }
  501. NSDictionary *infoDic = [info firstObject];
  502. _coinNum = minstr([infoDic valueForKey:@"coin"]);
  503. _coinL.text = _coinNum;
  504. [Config saveUserCoin:_coinNum];
  505. NSMutableDictionary *dic = @{
  506. @"avatar":[Config getUserAvatar],
  507. @"nickname":[Config getOwnNicename],
  508. @"uid":[Config getOwnID],
  509. @"lianfa":lianfa,
  510. @"paintedPath":[_paintedRegion getPaintedPointArray],
  511. @"paintedWidth":@([_paintedRegion getPaintedRegion].width),
  512. @"paintedHeight":@([_paintedRegion getPaintedRegion].height),
  513. }.mutableCopy;
  514. [dic addEntriesFromDictionary:infoDic];
  515. if ([_selModel.typeStr isEqual:@"2"]) {
  516. [weakSelf dismiss];
  517. }
  518. if (weakSelf.giftEvent) {
  519. weakSelf.giftEvent(0, dic);
  520. }
  521. if (_typeOfGift == ShowTypeOfGift_Bag) {
  522. [weakSelf pullData];
  523. }
  524. }else{
  525. [MBProgressHUD showError:msg];
  526. }
  527. } Fail:^(id fail) {
  528. [MBProgressHUD hideHUD];
  529. }];
  530. }
  531. #pragma mark - 直播送礼物结束
  532. -(void)startContinueSendTimer {
  533. _continueSendBtn.hidden = NO;
  534. _multipleIV.hidden = YES;
  535. _sendBtn.hidden = YES;
  536. _intervalTime = 5;
  537. [_continueSendBtn setTitle:[NSString stringWithFormat:@"%@\n %ds",YZMsg(@"连发"),_intervalTime] forState:UIControlStateNormal];
  538. if(_continueTimer == nil){
  539. _continueTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(continueSendInterval) userInfo:nil repeats:YES];
  540. }
  541. }
  542. -(void)continueSendInterval {
  543. _intervalTime-=1;
  544. [_continueSendBtn setTitle:[NSString stringWithFormat:@"%@\n %ds",YZMsg(@"连发"),_intervalTime] forState:UIControlStateNormal];
  545. if (_intervalTime == 0) {
  546. [self destroyTimer];
  547. _continueSendBtn.hidden = YES;
  548. _multipleIV.hidden = NO;
  549. // _sendBtn.hidden = NO;
  550. }
  551. }
  552. -(void)destroyTimer {
  553. if (_continueTimer) {
  554. [_continueTimer invalidate];
  555. _continueTimer = nil;
  556. }
  557. }
  558. -(void)setCoinListUI {
  559. _coinScroll.contentSize = CGSizeMake(_coinScroll.width, 0);
  560. if (!_coinL) {
  561. //图标
  562. UIImageView *coinIV = [[UIImageView alloc]init];
  563. [coinIV setImage:[UIImage imageNamed:@"礼物-金币"]];
  564. [_coinScroll addSubview:coinIV];
  565. [coinIV mas_makeConstraints:^(MASConstraintMaker *make) {
  566. make.left.equalTo(_coinScroll.mas_left).offset(10);
  567. make.centerY.equalTo(_coinScroll);
  568. make.width.height.mas_equalTo(15);
  569. }];
  570. //
  571. _coinL = [[UILabel alloc]init];
  572. _coinL.textColor = RGB_COLOR(@"#323232", 13);
  573. _coinL.font = SYS_Font(13);
  574. [_coinScroll addSubview:_coinL];
  575. [_coinL mas_makeConstraints:^(MASConstraintMaker *make) {
  576. make.left.equalTo(coinIV.mas_right).offset(5);
  577. make.centerY.equalTo(coinIV);
  578. }];
  579. //
  580. UIButton *chargeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  581. [chargeBtn setTitle:YZMsg(@"充值") forState:UIControlStateNormal];
  582. [chargeBtn setTitleColor:Pink_Cor forState:0];
  583. chargeBtn.titleLabel.font = SYS_Font(13);
  584. [chargeBtn addTarget:self action:@selector(clikcChargeBtn) forControlEvents:UIControlEventTouchUpInside];
  585. [_coinScroll addSubview:chargeBtn];
  586. chargeBtn.contentEdgeInsets = UIEdgeInsetsMake(5, 8, 5, 8);
  587. [chargeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  588. make.centerY.equalTo(coinIV);
  589. make.left.equalTo(_coinL.mas_right).offset(15);
  590. }];
  591. }
  592. _coinL.text = minstr(_coinNum);
  593. }
  594. -(void)clikcChargeBtn {
  595. [self dismiss];
  596. YBRechargeVC *chargeVC = [[YBRechargeVC alloc]init];
  597. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:chargeVC animated:YES];
  598. }
  599. #pragma mark - 礼物组 开始
  600. - (UIImageView *)multipleIV {
  601. if (!_multipleIV) {
  602. _multipleIV = [[UIImageView alloc]init];
  603. _multipleIV.image = [UIImage imageNamed:@"gift_send"];
  604. _multipleIV.userInteractionEnabled = YES;
  605. _multipleIV.hidden = YES;
  606. //选择数量按钮
  607. _multipleCountBtn = [UIButton buttonWithType:0];
  608. _multipleCountBtn.frame = CGRectMake(0, 0, 47, 26);
  609. [_multipleCountBtn setTitle:@"1" forState:0];
  610. [_multipleCountBtn setImage:[UIImage imageNamed:@"gift_top"] forState:0];
  611. [_multipleCountBtn addTarget:self action:@selector(multipleCountBtnClick) forControlEvents:UIControlEventTouchUpInside];
  612. _multipleCountBtn.titleLabel.font = [UIFont systemFontOfSize:13];
  613. [_multipleCountBtn setTitleColor:Pink_Cor forState:0];
  614. _multipleCountBtn.titleEdgeInsets = UIEdgeInsetsMake(0,-_multipleCountBtn.imageView.image.size.width, 0, _multipleCountBtn.imageView.image.size.width);
  615. _multipleCountBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 35, 0, 3);
  616. [_multipleIV addSubview:_multipleCountBtn];
  617. //发送按钮
  618. _multipleSendBtn = [UIButton buttonWithType:UIButtonTypeSystem];
  619. [_multipleSendBtn setTitle:YZMsg(@"赠送") forState:UIControlStateNormal];
  620. [_multipleSendBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  621. [_multipleSendBtn addTarget:self action:@selector(clickSendBtn:) forControlEvents:UIControlEventTouchUpInside];
  622. _multipleSendBtn.frame = CGRectMake(47,0,47,26);
  623. [_multipleIV addSubview:_multipleSendBtn];
  624. }
  625. return _multipleIV;
  626. }
  627. -(void)multipleCountBtnClick {
  628. if (!_multipleGiftCountBg) {
  629. _multipleGiftCountBg = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height)];
  630. _multipleGiftCountBg.backgroundColor = [UIColor clearColor];
  631. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideMultipleGiftCountBg)];
  632. [_multipleGiftCountBg addGestureRecognizer:tap];
  633. [self addSubview:_multipleGiftCountBg];
  634. UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(_window_width-110, _multipleGiftCountBg.height-26*_mutipleGiftA.count-18-40-ShowDiff, 47, 26*_mutipleGiftA.count+18)];
  635. imgView.image = [UIImage imageNamed:@"gift_nums"];
  636. imgView.userInteractionEnabled = YES;
  637. [_multipleGiftCountBg addSubview:imgView];
  638. for (int i = 0; i < _mutipleGiftA.count; i ++) {
  639. UIButton *btn = [UIButton buttonWithType:0];
  640. btn.frame = CGRectMake(0, i*26, 47, 26);
  641. [btn setTitle:_mutipleGiftA[i] forState:0];
  642. [btn setTitleColor:Pink_Cor forState:0];
  643. btn.titleLabel.font = [UIFont systemFontOfSize:10];
  644. [btn addTarget:self action:@selector(selectGiftNum:) forControlEvents:UIControlEventTouchUpInside];
  645. [imgView addSubview:btn];
  646. }
  647. }else{
  648. _multipleGiftCountBg.hidden = NO;
  649. }
  650. [_multipleCountBtn setImage:[UIImage imageNamed:@"gift_down"] forState:0];
  651. }
  652. -(void)hideMultipleGiftCountBg {
  653. _multipleGiftCountBg.hidden = YES;
  654. [_multipleCountBtn setImage:[UIImage imageNamed:@"gift_top"] forState:0];
  655. }
  656. - (void)selectGiftNum:(UIButton *)sender{
  657. _multipleGiftCountBg.hidden = YES;
  658. [_multipleCountBtn setTitle:sender.titleLabel.text forState:0];
  659. [_multipleCountBtn setImage:[UIImage imageNamed:@"gift_top"] forState:0];
  660. }
  661. #pragma mark - 礼物组 结束
  662. @end