GiftView.m 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353
  1. //
  2. // GiftView.m
  3. // BuguLive
  4. //
  5. // Created by xfg on 16/5/20.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "GiftView.h"
  9. #import "SDCycleScrollView2.h"
  10. #import "BogoNobleViewController.h"
  11. #import "BogoLiveGiftViewPeopleCell.h"
  12. #import "RoomUserInfo.h"
  13. #import "GiftQuantityModel.h"
  14. #define kGiftHorizontalNum 4 // 礼物横向的个数
  15. #define kContinueContainerViewWidth 80 // 连发按钮宽、高度
  16. @interface GiftView()<GiftSubViewDelegate,UIScrollViewDelegate,UIGestureRecognizerDelegate>
  17. @property (nonatomic, strong) NSMutableArray *bottomViewArray;
  18. @property (nonatomic, assign) NSInteger giftVerticalNum; //礼物纵向的个数
  19. @property (nonatomic, strong) NSMutableArray *giftMArray;
  20. @property (nonatomic, strong) NSMutableArray *itemArray; //保存GiftSubView的数组
  21. @property (nonatomic, strong) GiftModel *currentGiftModel; //当前选中的GiftModel
  22. @property (nonatomic, strong) UIView *rechargeContainerView; //充值容器视图
  23. @property (nonatomic, strong) UILabel *diamondsLabel; //账户剩余钻石
  24. @property (nonatomic, strong) UIImageView *rechargeImgView; //充值图标
  25. @property (nonatomic, strong) QMUIButton *rechargeBtn; //充值按钮
  26. @property (nonatomic, strong) UIButton *continueBtn; //连发按钮
  27. @property (nonatomic, strong) UICountingLabel *sendedTimeLabel; //发送次数
  28. @property (nonatomic, assign) NSInteger sendedTime; //发送次数
  29. @property (nonatomic, assign) NSInteger sendedTimeCopy; //发送次数
  30. @property (nonatomic, assign) int upSelectedIndex; //上一次选中的index
  31. @property(nonatomic, strong) QMUIPopupMenuView *popView;
  32. @property(nonatomic, strong) GiftQuantityModel *numberModel;
  33. @property(nonatomic, strong) UIImageView *diamondsImgView;
  34. //@property (nonatomic, strong) GiftGroupView *groupView;
  35. @property(nonatomic, strong) UIImageView *bgImgView;
  36. @property(nonatomic, strong) UIView *bottomNumberView;
  37. @property(nonatomic, strong) UICollectionView *peopleCollectionView;
  38. @property(nonatomic, strong) NSMutableArray *newUserArray;
  39. @property(nonatomic, strong) NSString *selectUser;
  40. @end
  41. @implementation GiftView
  42. - (instancetype)initWithFrame:(CGRect)frame
  43. {
  44. if (self = [super initWithFrame:frame])
  45. {
  46. [self initUI];
  47. }
  48. return self;
  49. }
  50. - (void)setIsHost:(BOOL)isHost
  51. {
  52. _isHost = isHost;
  53. if(_isHost && !self.isVoice)
  54. {
  55. self.bottomContainerView.hidden = YES;
  56. }
  57. }
  58. -(void)reequestUserList
  59. {
  60. __weak __typeof(self)weakSelf = self;
  61. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  62. [dict setValue:@"voice" forKey:@"ctl"];
  63. [dict setValue:@"get_wheat_user" forKey:@"act"];
  64. NSString *roomID = @"";
  65. if([self.delegate respondsToSelector:@selector(roomId)])
  66. {
  67. roomID = [self.delegate roomId];
  68. }
  69. [dict setValue:roomID forKey:@"room_id"];
  70. // [[BGHUDHelper sharedInstance] syncLoading];
  71. [[NetHttpsManager manager] POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  72. if ([responseJson toInt:@"status"] == 1) {
  73. weakSelf.newUserArray = [NSMutableArray array];
  74. NSMutableArray *data = responseJson[@"data"];
  75. if(data.count > 0)
  76. {
  77. RoomUserInfo *model = [RoomUserInfo mj_objectWithKeyValues:data[0]];
  78. [GlobalVariables sharedInstance].giftSelecUserId = model.user_id;
  79. }
  80. else
  81. {
  82. [GlobalVariables sharedInstance].giftSelecUserId = nil;
  83. }
  84. int i = 0;
  85. for (NSDictionary *dict in data) {
  86. RoomUserInfo *model = [RoomUserInfo mj_objectWithKeyValues:dict];
  87. if(i == 0)
  88. {
  89. model.selected = YES;
  90. }
  91. [weakSelf.newUserArray addObject:model];
  92. i++;
  93. }
  94. [self.peopleCollectionView reloadData];
  95. }
  96. } FailureBlock:^(NSError *error) {
  97. // [[BGHUDHelper sharedInstance] syncStopLoading];
  98. }];
  99. }
  100. -(void)initUI
  101. {
  102. CGRect frame = self.frame;
  103. self.numberModel = [GlobalVariables sharedInstance].giftQuantityModelList[0];
  104. self.backgroundColor = kClearColor;
  105. // 毛玻璃效果
  106. // UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
  107. // UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
  108. // effectView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
  109. // [self addSubview:effectView];
  110. self.bgImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
  111. self.bgImgView.image = [UIImage imageNamed:@"mg_live_gift_bgImgView"];
  112. self.bgImgView.userInteractionEnabled = YES;
  113. [self addSubview:self.bgImgView];
  114. _itemArray = [NSMutableArray array];
  115. _bottomViewArray = [NSMutableArray array];
  116. UIView *bottomContainerView = [[UIView alloc] initWithFrame:CGRectMake(0, frame.size.height-kSendGiftContrainerHeight, frame.size.width, kSendGiftContrainerHeight + MG_BOTTOM_MARGIN + 50)];
  117. bottomContainerView.backgroundColor = [UIColor colorWithHexString:@"#221336"];
  118. /*
  119. self.bgImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
  120. self.bgImgView.image = [UIImage imageNamed:@"mg_live_gift_bgImgView"];
  121. self.bgImgView.userInteractionEnabled = YES;
  122. [self addSubview:self.bgImgView];
  123. _itemArray = [NSMutableArray array];
  124. _bottomViewArray = [NSMutableArray array];
  125. UIView *bottomContainerView = [[UIView alloc] initWithFrame:CGRectMake(0, frame.size.height-kSendGiftContrainerHeight, frame.size.width, kSendGiftContrainerHeight + MG_BOTTOM_MARGIN + 50)];
  126. UIView *back = [[UIView alloc] initWithFrame:bottomContainerView.frame];
  127. back.backgroundColor = [UIColor colorWithHexString:@"#221336"];
  128. [self addSubview:back];
  129. bottomContainerView.backgroundColor = [UIColor colorWithHexString:@"#221336"];*/
  130. [self addSubview:bottomContainerView];
  131. _rechargeContainerView = [[UIView alloc]initWithFrame:CGRectMake(kDefaultMargin, kDefaultMargin, kScreenW, kSendGiftContrainerHeight-kDefaultMargin*2)];
  132. _rechargeContainerView.backgroundColor = [UIColor colorWithHexString:@"#221336"];
  133. // kGrayTransparentColor3_1;
  134. [self addSubview:bottomContainerView];
  135. self.bottomContainerView = bottomContainerView;
  136. _rechargeContainerView = [[UIView alloc]initWithFrame:CGRectMake(kDefaultMargin, kDefaultMargin, kScreenW, kSendGiftContrainerHeight-kDefaultMargin*2)];
  137. _rechargeContainerView.backgroundColor = [UIColor colorWithHexString:@"#221336"];
  138. [bottomContainerView addSubview:_rechargeContainerView];
  139. // kGrayTransparentColor5;
  140. /*
  141. _rechargeContainerView.userInteractionEnabled = YES;
  142. _rechargeContainerView.layer.cornerRadius = CGRectGetHeight(_rechargeContainerView.frame)/2;
  143. _rechargeContainerView = [[UIView alloc]initWithFrame:CGRectMake(kDefaultMargin, kDefaultMargin, kScreenW, kSendGiftContrainerHeight-kDefaultMargin*2)];
  144. _rechargeContainerView.backgroundColor = [UIColor colorWithHexString:@"#221336"];
  145. // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickRechargeAction)];
  146. // tap.delegate = self;
  147. // [_rechargeContainerView addGestureRecognizer:tap];
  148. //2020-1-15 修改礼物界面
  149. UILabel *Label = [[UILabel alloc]initWithFrame:CGRectMake(kDefaultMargin, 0, 50, CGRectGetHeight(_rechargeContainerView.frame))];
  150. Label.font = [UIFont systemFontOfSize:14.0];
  151. Label.textColor = kWhiteColor;
  152. Label.text = ASLocalizedString(@"余额:");
  153. [self.topView addSubview:Label];
  154. _diamondsImgView = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(Label.frame),(CGRectGetHeight(_rechargeContainerView.frame)-15)/2, 15, 15)];
  155. _diamondsImgView.contentMode = UIViewContentModeScaleAspectFit;
  156. [_diamondsImgView setImage:[UIImage imageNamed:@"com_diamond_1"]];
  157. _diamondsLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(_diamondsImgView.frame)+kDefaultMargin, 0, 50, CGRectGetHeight(_rechargeContainerView.frame))];
  158. _diamondsLabel.font = [UIFont systemFontOfSize:14.0];
  159. _diamondsLabel.textAlignment = NSTextAlignmentRight;
  160. _diamondsLabel.textColor = kWhiteColor;
  161. _diamondsLabel.text = @"0";
  162. _rechargeImgView = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(_diamondsLabel.frame)+kDefaultMargin,(CGRectGetHeight(_rechargeContainerView.frame)-16)/2, 16, 16)];
  163. _rechargeImgView.contentMode = UIViewContentModeScaleAspectFit;
  164. _rechargeImgView.hidden = YES;
  165. */
  166. // [_rechargeImgView setImage:[UIImage imageNamed:@"lr_gift_list_recharge"]];
  167. //2020-1-15 修改礼物界面
  168. UILabel *Label = [[UILabel alloc]initWithFrame:CGRectMake(kDefaultMargin, 0, 60, CGRectGetHeight(_rechargeContainerView.frame))];
  169. Label.font = [UIFont systemFontOfSize:14.0];
  170. Label.textColor = kWhiteColor;
  171. Label.text = ASLocalizedString(@"余额:");
  172. // [_rechargeContainerView addSubview:Label];
  173. UIImageView *diamondsImgView = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(Label.frame),(CGRectGetHeight(_rechargeContainerView.frame)-15)/2, 15, 15)];
  174. diamondsImgView.contentMode = UIViewContentModeScaleAspectFit;
  175. [diamondsImgView setImage:[UIImage imageNamed:@"com_diamond_1"]];
  176. // [_rechargeContainerView addSubview:diamondsImgView];
  177. _diamondsImgView = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(Label.frame),(CGRectGetHeight(_rechargeContainerView.frame)-15)/2, 15, 15)];
  178. _diamondsImgView.contentMode = UIViewContentModeScaleAspectFit;
  179. [_diamondsImgView setImage:[UIImage imageNamed:@"com_diamond_1"]];
  180. _diamondsLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(_diamondsImgView.frame)+kDefaultMargin, 0, 50, CGRectGetHeight(_rechargeContainerView.frame))];
  181. _diamondsLabel.font = [UIFont systemFontOfSize:14.0];
  182. _diamondsLabel.textAlignment = NSTextAlignmentRight;
  183. _diamondsLabel.textColor = kWhiteColor;
  184. _diamondsLabel.text = @"0";
  185. _rechargeImgView = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(_diamondsLabel.frame)+kDefaultMargin,(CGRectGetHeight(_rechargeContainerView.frame)-16)/2, 16, 16)];
  186. _rechargeImgView.contentMode = UIViewContentModeScaleAspectFit;
  187. _rechargeImgView.hidden = YES;
  188. _rechargeBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  189. _rechargeBtn.frame = CGRectMake(_diamondsLabel.right + kDefaultMargin, (CGRectGetHeight(_rechargeContainerView.frame)-20)/2, 100, 20);
  190. _rechargeBtn.layer.cornerRadius = 20 / 2;
  191. _rechargeBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  192. _rechargeBtn.frame = CGRectMake(_diamondsLabel.right + kDefaultMargin, 5, 100, 20);
  193. _rechargeBtn.layer.cornerRadius = 20 / 2;
  194. [_rechargeBtn setTitleColor:[UIColor colorWithHexString:@"#C28CF8"] forState:UIControlStateNormal];
  195. _rechargeBtn.userInteractionEnabled = YES;
  196. // _rechargeBtn.enabled = NO;
  197. [_rechargeBtn setTitle:ASLocalizedString(@"充值 >")forState:UIControlStateNormal];
  198. _rechargeBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  199. _rechargeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
  200. [_rechargeBtn setImagePosition:QMUIButtonImagePositionRight];
  201. _rechargeBtn.spacingBetweenImageAndTitle = 2;
  202. _rechargeBtn.backgroundColor = kClearColor;
  203. [_rechargeBtn addTarget:self action:@selector(clickRechargeAction) forControlEvents:UIControlEventTouchUpInside];
  204. //[_rechargeBtn setImage:[UIImage imageNamed:@"lr_gift_list_recharge_next"] forState:UIControlStateNormal];
  205. _rechargeBtn.layer.borderColor = [UIColor colorWithHexString:@"#C28CF8"].CGColor;
  206. _rechargeBtn.layer.borderWidth = 1.5f;
  207. _sendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  208. _sendBtn.frame = CGRectMake(frame.size.width-60-kDefaultMargin - 10, kDefaultMargin/2, 70, kSendGiftContrainerHeight-kDefaultMargin);
  209. _numberBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  210. _numberBtn.frame = CGRectMake(_sendBtn.left - 50, kDefaultMargin/2, 90, kSendGiftContrainerHeight-kDefaultMargin);
  211. // [_numberBtn setTitle:@"X 1" forState:UIControlStateNormal];
  212. [self resetNumber];
  213. // [_sendBtn setImage:[UIImage imageNamed:@"ic_gift_send"] forState:UIControlStateNormal];
  214. // [_sendBtn setTitleColor:kAppGrayColor1 forState:UIControlStateNormal];
  215. // [_sendBtn setBackgroundColor:[UIColor lightGrayColor]];
  216. // [_numberBtn setTitle:ASLocalizedString(@"发送")forState:UIControlStateNormal];
  217. // [_numberBtn setBackgroundImage:[UIImage imageNamed:@"发送按钮"] forState:UIControlStateNormal];
  218. /*
  219. _numberBtn.layer.cornerRadius = CGRectGetHeight(_numberBtn.frame)/2;
  220. _numberBtn.backgroundColor = RGB(55,34,86);
  221. _numberBtn.titleLabel.textAlignment = NSTextAlignmentLeft;
  222. _numberBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  223. _numberBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
  224. _numberBtn.layer.masksToBounds = YES;
  225. _numberBtn.titleLabel.font = kAppMiddleTextFont;
  226. [_numberBtn addTarget:self action:@selector(setNumAction:) forControlEvents:UIControlEventTouchUpInside];
  227. [bottomContainerView addSubview:_numberBtn];*/
  228. // _numberBtn.layer.cornerRadius = CGRectGetHeight(_numberBtn.frame)/2;
  229. // _numberBtn.backgroundColor = RGB(55,34,86);
  230. // _numberBtn.titleLabel.textAlignment = NSTextAlignmentLeft;
  231. // _numberBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  232. // _numberBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
  233. //
  234. // _numberBtn.layer.masksToBounds = YES;
  235. // _numberBtn.titleLabel.font = kAppMiddleTextFont;
  236. // [_numberBtn addTarget:self action:@selector(setNumAction:) forControlEvents:UIControlEventTouchUpInside];
  237. // [bottomContainerView addSubview:_numberBtn];
  238. [bottomContainerView addSubview:self.bottomNumberView];
  239. // [_sendBtn setTitle:ASLocalizedString(@"送礼")forState:UIControlStateNormal];
  240. // [_sendBtn setImage:[UIImage imageNamed:@"ic_gift_send"] forState:UIControlStateNormal];
  241. // [_sendBtn setTitleColor:kAppGrayColor1 forState:UIControlStateNormal];
  242. // [_sendBtn setBackgroundColor:[UIColor lightGrayColor]];
  243. [_sendBtn setTitle:ASLocalizedString(@"发送")forState:UIControlStateNormal];
  244. [_sendBtn setBackgroundImage:[UIImage imageNamed:@"发送按钮"] forState:UIControlStateNormal];
  245. _sendBtn.layer.cornerRadius = CGRectGetHeight(_sendBtn.frame)/2;
  246. _sendBtn.layer.masksToBounds = YES;
  247. _sendBtn.titleLabel.font = kAppMiddleTextFont;
  248. [_sendBtn addTarget:self action:@selector(senGiftAction:) forControlEvents:UIControlEventTouchUpInside];
  249. [bottomContainerView addSubview:_sendBtn];
  250. _continueContainerView = [[UIView alloc]initWithFrame:CGRectMake(frame.size.width-kContinueContainerViewWidth-kDefaultMargin*2, frame.size.height-kContinueContainerViewWidth-kDefaultMargin*2-20, kContinueContainerViewWidth, kContinueContainerViewWidth+20)];
  251. _continueContainerView.backgroundColor = [UIColor clearColor];
  252. [self addSubview:_continueContainerView];
  253. _continueContainerView.hidden = YES;
  254. _continueBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  255. _continueBtn.frame = CGRectMake(0, 0, kContinueContainerViewWidth, kContinueContainerViewWidth);
  256. [_continueBtn setImage:[UIImage imageNamed:@"lr_send_gift_normal"] forState:UIControlStateNormal];
  257. [_continueBtn setImage:[UIImage imageNamed:@"lr_send_gift_selected"] forState:UIControlStateHighlighted];
  258. [_continueBtn setBackgroundColor:[UIColor clearColor]];
  259. [_continueBtn addTarget:self action:@selector(senGiftAction:) forControlEvents:UIControlEventTouchUpInside];
  260. [_continueContainerView addSubview:_continueBtn];
  261. UILabel *continueLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, kContinueContainerViewWidth/2-21, kContinueContainerViewWidth, 21)];
  262. continueLabel.font = [UIFont systemFontOfSize:15.0];
  263. continueLabel.textAlignment = NSTextAlignmentCenter;
  264. continueLabel.textColor = [UIColor whiteColor];
  265. continueLabel.text = ASLocalizedString(@"连发");
  266. [_continueContainerView addSubview:continueLabel];
  267. _decTimeCLabel = [[UICountingLabel alloc] initWithFrame:CGRectMake(0, kContinueContainerViewWidth/2, kContinueContainerViewWidth, 21)];
  268. _decTimeCLabel.method = UILabelCountingMethodLinear;
  269. _decTimeCLabel.textAlignment = NSTextAlignmentCenter;
  270. _decTimeCLabel.textColor = [UIColor whiteColor];
  271. [_continueContainerView addSubview:_decTimeCLabel];
  272. NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
  273. formatter.numberStyle = kCFNumberFormatterDecimalStyle;
  274. _decTimeCLabel.formatBlock = ^NSString* (CGFloat value)
  275. {
  276. NSString* formatted = [formatter stringFromNumber:@((int)value)];
  277. return formatted;
  278. };
  279. _decTimeCLabel.method = UILabelCountingMethodLinear;
  280. _sendedTimeLabel = [[UICountingLabel alloc] initWithFrame:CGRectMake(0, -10, kContinueContainerViewWidth, 21)];
  281. _sendedTimeLabel.method = UILabelCountingMethodEaseOut;
  282. _sendedTimeLabel.textAlignment = NSTextAlignmentCenter;
  283. _sendedTimeLabel.textColor = kWhiteColor;
  284. [_continueContainerView addSubview:_sendedTimeLabel];
  285. _sendedTimeLabel.formatBlock = ^NSString* (CGFloat value)
  286. {
  287. NSString* formatted = [formatter stringFromNumber:@((int)value)];
  288. return formatted;
  289. };
  290. _sendedTimeLabel.method = UILabelCountingMethodLinear;
  291. }
  292. - (void)resetNumber {
  293. [_numberBtn setTitle:self.numberModel.title forState:UIControlStateNormal];
  294. }
  295. #pragma mark 结束连发
  296. - (void)finishContinue
  297. {
  298. _sendBtn.hidden = NO;
  299. _continueContainerView.hidden = YES;
  300. }
  301. -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
  302. if ([touch.view isKindOfClass:[QMUIButton class]]) {
  303. return NO;
  304. }
  305. return YES;
  306. }
  307. #pragma mark 点击充值
  308. - (void)clickRechargeAction
  309. {
  310. if (_delegate && [_delegate respondsToSelector:@selector(showRechargeView:)])
  311. {
  312. [_delegate showRechargeView:self];
  313. }
  314. }
  315. #pragma mark 设置当前钻石数量
  316. - (void)setDiamondsLabelTxt:(NSString *)txt
  317. {
  318. _diamondsLabel.text = txt;
  319. CGSize titleSize = [txt boundingRectWithSize:CGSizeMake(100, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} context:nil].size;
  320. _diamondsLabel.frame = CGRectMake(_diamondsLabel.frame.origin.x, _diamondsLabel.frame.origin.y, titleSize.width, _diamondsLabel.frame.size.height);
  321. _rechargeBtn.left = _diamondsLabel.right + kDefaultMargin;
  322. _rechargeImgView.frame = CGRectMake(_diamondsLabel.left + kDefaultMargin,_rechargeImgView.frame.origin.y, _rechargeImgView.frame.size.width, _rechargeImgView.frame.size.height);
  323. _rechargeContainerView.frame = CGRectMake(CGRectGetMinX(_rechargeContainerView.frame), CGRectGetMinY(_rechargeContainerView.frame), kScreenW, CGRectGetHeight(_rechargeContainerView.frame));
  324. }
  325. #pragma mark
  326. - (void)setGiftView:(NSMutableArray *)giftMArray
  327. {
  328. [_itemArray removeAllObjects];
  329. [_bottomViewArray removeAllObjects];
  330. NSMutableArray *tempOutArray = [NSMutableArray array];
  331. for (NSInteger i = 0; i < giftMArray.count; i++) {
  332. GiftModel *outModel = giftMArray[i];
  333. NSMutableArray *tempInArray = [NSMutableArray array];
  334. for (NSInteger j = 0; j < outModel.list.count; j++) {
  335. NSDictionary *dict = outModel.list[j];
  336. GiftModel *inModel = [GiftModel mj_objectWithKeyValues:dict];
  337. [tempInArray addObject:inModel];
  338. }
  339. [tempOutArray addObject:tempInArray];
  340. }
  341. _giftMArray = tempOutArray;
  342. [self createGiftSubView:giftMArray];
  343. }
  344. -(void)reloadBag
  345. {
  346. [[GiftListManager sharedInstance] reloadGiftList];
  347. [GiftListManager sharedInstance].relodComplete = ^{
  348. [self removeAllSubviews];
  349. [self initUI];
  350. NSMutableArray *list = [GiftListManager sharedInstance].giftMArray;
  351. NSMutableArray *giftMArray = [NSMutableArray array];
  352. if (list && [list isKindOfClass:[NSArray class]])
  353. {
  354. for (NSDictionary *key in list)
  355. {
  356. GiftModel *giftModel = [GiftModel mj_objectWithKeyValues:key];
  357. [giftMArray addObject:giftModel];
  358. }
  359. }
  360. BOOL ret = NO;
  361. for (GiftModel *giftModel in giftMArray) {
  362. if (giftModel.list.count > 4) {
  363. ret = YES;
  364. break;
  365. }
  366. }
  367. WeakSelf
  368. [self setGiftView:giftMArray];
  369. [self changeMoney];
  370. [self.scrollView scrollRectToVisible:CGRectMake(self.scrollView.width, 0, self.scrollView.width, self.scrollView.height) animated:NO];
  371. [self.topView resetIndexs:1];
  372. };
  373. }
  374. - (void)setHidden:(BOOL)hidden
  375. {
  376. [super setHidden:hidden];
  377. [[GiftListManager sharedInstance] reloadGiftList];
  378. [self reequestUserList];
  379. if(self.isChat)
  380. {
  381. if(hidden == NO)
  382. {
  383. [self removeAllSubviews];
  384. [self initUI];
  385. if(_isHost && !self.isVoice)
  386. {
  387. self.bottomContainerView.hidden = YES;
  388. }
  389. NSMutableArray *list = [GiftListManager sharedInstance].giftMArray;
  390. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  391. [mDict setObject:@"app" forKey:@"ctl"];
  392. [mDict setObject:@"prop" forKey:@"act"];
  393. [mDict setObject:@"1" forKey:@"type"];
  394. FWWeakify(self)
  395. [[NetHttpsManager manager] POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  396. FWStrongify(self)
  397. if ([responseJson toInt:@"status"] == 1)
  398. {
  399. NSArray *list = responseJson[@"list"];
  400. NSMutableArray *giftMArray = [NSMutableArray array];
  401. if (list && [list isKindOfClass:[NSArray class]])
  402. {
  403. for (NSDictionary *key in list)
  404. {
  405. GiftModel *giftModel = [GiftModel mj_objectWithKeyValues:key];
  406. [giftMArray addObject:giftModel];
  407. }
  408. }
  409. BOOL ret = NO;
  410. for (GiftModel *giftModel in giftMArray) {
  411. if (giftModel.list.count > 4) {
  412. ret = YES;
  413. break;
  414. }
  415. }
  416. WeakSelf
  417. [self setGiftView:giftMArray];
  418. [self changeMoney];
  419. }
  420. } FailureBlock:^(NSError *error) {
  421. }];
  422. }
  423. }
  424. else
  425. {
  426. [GiftListManager sharedInstance].relodComplete = ^{
  427. if(hidden == NO)
  428. {
  429. [self removeAllSubviews];
  430. [self initUI];
  431. if(_isHost && !self.isVoice)
  432. {
  433. self.bottomContainerView.hidden = YES;
  434. }
  435. NSMutableArray *list = [GiftListManager sharedInstance].giftMArray;
  436. NSMutableArray *giftMArray = [NSMutableArray array];
  437. if (list && [list isKindOfClass:[NSArray class]])
  438. {
  439. for (NSDictionary *key in list)
  440. {
  441. GiftModel *giftModel = [GiftModel mj_objectWithKeyValues:key];
  442. [giftMArray addObject:giftModel];
  443. }
  444. }
  445. BOOL ret = NO;
  446. for (GiftModel *giftModel in giftMArray) {
  447. if (giftModel.list.count > 4) {
  448. ret = YES;
  449. break;
  450. }
  451. }
  452. WeakSelf
  453. [self setGiftView:giftMArray];
  454. [self changeMoney];
  455. }
  456. };
  457. }
  458. }
  459. - (void)changeMoney
  460. {
  461. FWWeakify(self)
  462. [[IMAPlatform sharedInstance].host getMyInfo:^(AppBlockModel *blockModel) {
  463. FWStrongify(self)
  464. long currentDiamonds = [[IMAPlatform sharedInstance].host getDiamonds];
  465. [self setDiamondsLabelTxt:[NSString stringWithFormat:@"%ld",(long)currentDiamonds]];
  466. }];
  467. }
  468. #pragma mark 创建每一项
  469. - (void)handleNunberEvent:(QMUIFillButton *)sender {
  470. for (int i=0; i<_bottomNumberView.subviews.count; i++) {
  471. if([_bottomNumberView.subviews[i] isKindOfClass:[QMUIFillButton class]])
  472. {
  473. QMUIButton *btn = _bottomNumberView.subviews[i];
  474. btn.selected = NO;
  475. }
  476. }
  477. self.numberModel = [sender qmui_getBoundObjectForKey:@"model"];
  478. sender.selected = YES;
  479. }
  480. -(UIView *)bottomNumberView
  481. {
  482. if(_bottomNumberView == nil)
  483. {
  484. _bottomNumberView = [[UIView alloc] init];
  485. _bottomNumberView.frame = CGRectMake(0, 0, self.width, 40);
  486. int btnWidth = 45;
  487. // _bottomNumberView.hidden = YES;
  488. int y = 5;
  489. int x = 45;
  490. UILabel *lab = [[UILabel alloc] init];
  491. lab.text = @"number";
  492. lab.font = [UIFont systemFontOfSize:12];
  493. lab.textColor = kWhiteColor;
  494. [_bottomNumberView addSubview:lab];
  495. lab.frame = CGRectMake(5, 5, 60, 40);
  496. NSMutableArray *itemArr = [NSMutableArray array];
  497. for (int i =0 ; i<[GlobalVariables sharedInstance].giftQuantityModelList.count; i++) {
  498. GiftQuantityModel *model = [GlobalVariables sharedInstance].giftQuantityModelList[i];
  499. __weak __typeof(self)weakSelf = self;
  500. QMUIFillButton *btn = [[QMUIFillButton alloc] init];
  501. if(i == 0)
  502. {
  503. btn.selected = YES;
  504. }
  505. btn.backgroundColor = [kWhiteColor colorWithAlphaComponent:0.1];
  506. btn.titleLabel.font = [UIFont systemFontOfSize:11];
  507. [btn setTitle:model.num forState:UIControlStateNormal];
  508. int xx = x + i*(btnWidth + 10);
  509. btn.frame = CGRectMake(xx, y, btnWidth, 32);
  510. [btn setTitleColor:kWhiteColor forState:UIControlStateNormal];
  511. [btn qmui_bindObject:model forKey:@"model"];
  512. [btn setTitleColor:[UIColor colorWithHexString:@"#C28CF8"] forState:UIControlStateSelected];
  513. [btn addTarget:self action:@selector(handleNunberEvent:) forControlEvents:UIControlEventTouchUpInside];
  514. [_bottomNumberView addSubview:btn];
  515. }
  516. return _bottomNumberView;
  517. }
  518. else
  519. {
  520. return _bottomNumberView;
  521. }
  522. //
  523. // NSMutableArray *itemArr = [NSMutableArray array];
  524. // for (int i =0 ; i<[GlobalVariables sharedInstance].giftQuantityModelList.count; i++) {
  525. // GiftQuantityModel *model = [GlobalVariables sharedInstance].giftQuantityModelList[i];
  526. // __weak __typeof(self)weakSelf = self;
  527. // QMUIPopupMenuButtonItem *qmuiItem = [QMUIPopupMenuButtonItem itemWithImage:nil title:model.title handler:^(QMUIPopupMenuButtonItem *aItem) {
  528. // weakSelf.numberModel = [GlobalVariables sharedInstance].giftQuantityModelList[i];
  529. // [weakSelf resetNumber];
  530. // [self.popView hideWithAnimated:NO];
  531. // }];
  532. //
  533. // [qmuiItem qmui_bindObject:model forKey:@"model"];
  534. //
  535. // [itemArr addObject:qmuiItem];
  536. // }
  537. }
  538. - (void)createGiftSubView:(NSMutableArray *)arrayList
  539. {
  540. //创建标题数组
  541. NSMutableArray *titleArray = [NSMutableArray array];
  542. for (GiftModel *model in arrayList) {
  543. [titleArray addObject:model.name];
  544. }
  545. //创建礼物分类
  546. int height = kRealValue(53);
  547. if(self.isVoice)
  548. {
  549. height = kRealValue(53) + 44;
  550. }
  551. GiftGroupView *groupView = [[GiftGroupView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, height) TitleArray:titleArray];
  552. [groupView setClickGiftGroupBtnBlock:^(NSInteger index) {
  553. [self.scrollView scrollRectToVisible:CGRectMake(index*self.scrollView.width, 0, self.scrollView.width, self.scrollView.height) animated:YES];
  554. }];
  555. // groupView.height += 44;
  556. // self.y -= 44;
  557. [self addSubview:groupView];
  558. if(self.isVoice == YES)
  559. {
  560. [groupView addSubview:self.peopleCollectionView];
  561. self.peopleCollectionView.backgroundColor = kClearColor;
  562. UILabel *lab = [[UILabel alloc] init];
  563. lab.text = @"送给";
  564. lab.textColor = kWhiteColor;
  565. lab.font = [UIFont systemFontOfSize:14];
  566. [groupView addSubview:lab];
  567. [lab mas_makeConstraints:^(MASConstraintMaker *make) {
  568. make.left.equalTo(groupView).offset(5);
  569. make.centerY.equalTo(self.peopleCollectionView);
  570. }];
  571. [self.peopleCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  572. make.left.equalTo(lab.mas_right).offset(5);
  573. make.right.equalTo(groupView).offset(-5);
  574. make.height.equalTo(@44);
  575. // make.width.equalTo(groupView);
  576. make.top.equalTo(@(height - 44));
  577. }];
  578. }
  579. self.topView = groupView;
  580. [self.topView addSubview:_diamondsImgView];
  581. [self.topView addSubview:_diamondsLabel];
  582. [self.topView addSubview:_rechargeImgView];
  583. [self.topView addSubview:_rechargeBtn];
  584. //
  585. // NSMutableArray *itemArr = [NSMutableArray array];
  586. // for (int i =0 ; i<[GlobalVariables sharedInstance].giftQuantityModelList.count; i++) {
  587. // GiftQuantityModel *model = [GlobalVariables sharedInstance].giftQuantityModelList[i];
  588. // __weak __typeof(self)weakSelf = self;
  589. // QMUIPopupMenuButtonItem *qmuiItem = [QMUIPopupMenuButtonItem itemWithImage:nil title:model.title handler:^(QMUIPopupMenuButtonItem *aItem) {
  590. // weakSelf.numberModel = [GlobalVariables sharedInstance].giftQuantityModelList[i];
  591. // [weakSelf resetNumber];
  592. // [self.popView hideWithAnimated:NO];
  593. // }];
  594. //
  595. // [qmuiItem qmui_bindObject:model forKey:@"model"];
  596. //
  597. // [itemArr addObject:qmuiItem];
  598. // }
  599. [_rechargeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  600. // make.left.equalTo(self.diamondsImgView);
  601. make.right.equalTo(self.topView).priorityHigh();
  602. make.width.equalTo(@80).priorityHigh();;
  603. make.height.equalTo(@22);
  604. make.top.equalTo(self.topView).offset(5);
  605. }];
  606. [_diamondsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  607. make.right.equalTo(self.topView).offset(-5);
  608. make.top.equalTo(self.rechargeBtn.mas_bottom).offset(5);
  609. }];
  610. [_diamondsImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  611. make.height.equalTo(@18);
  612. make.width.equalTo(@18);
  613. make.right.equalTo(_diamondsLabel.mas_left).offset(-5);
  614. make.centerY.equalTo(_diamondsLabel);
  615. }];
  616. UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, groupView.bottom, self.frame.size.width, self.frame.size.height-kSendGiftContrainerHeight - groupView.height)];
  617. scrollView.contentSize = CGSizeMake(arrayList.count * self.width, scrollView.height);
  618. scrollView.pagingEnabled = YES;
  619. scrollView.delegate = self;
  620. [self addSubview:scrollView];
  621. self.scrollView = scrollView;
  622. for (NSInteger index = 0; index < arrayList.count; index++) {
  623. //bottomViewArray重置
  624. [_bottomViewArray removeAllObjects];
  625. NSMutableArray *itemSubArray = [NSMutableArray array];
  626. //得到第一层
  627. GiftModel *model = arrayList[index];
  628. //得到第一个分类下的礼物集合
  629. NSArray *newArrayList = model.list;
  630. //计算出需要几个轮播图的ImageView
  631. NSUInteger num = [newArrayList count]/8;
  632. //有余数加1
  633. if ([newArrayList count]%8)
  634. {
  635. num ++;
  636. }
  637. //一共需要创建多少轮播图的子View
  638. int i= 0;
  639. for (int k=0; k<num; k++)
  640. {
  641. CGFloat btn_x_2 = -1;
  642. CGFloat btn_y_2 = -1;
  643. //底部视图
  644. UIView *bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.scrollView.height)];
  645. bottomView.backgroundColor = [UIColor clearColor];
  646. //礼物容器视图
  647. UIView *giftListContrainerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, bottomView.frame.size.width, bottomView.frame.size.height-kDefaultMargin*4)];
  648. giftListContrainerView.backgroundColor = [UIColor clearColor];
  649. giftListContrainerView.clipsToBounds = YES;
  650. [bottomView addSubview:giftListContrainerView];
  651. // if ([newArrayList count]>4)
  652. // {
  653. // _giftVerticalNum = 2;
  654. // }
  655. // else if([newArrayList count]>0 && [newArrayList count]<5)
  656. // {
  657. // _giftVerticalNum = 1;
  658. // }
  659. //纵向个数为2
  660. _giftVerticalNum = 2;
  661. NSUInteger counttag = 0;
  662. if (num == 1)
  663. {
  664. //如果只有1个礼物,计数就是礼物的数量
  665. counttag = [newArrayList count];
  666. }
  667. else if (k<num-1)
  668. {
  669. counttag = k*8+8;
  670. }
  671. else
  672. {
  673. counttag = [newArrayList count];
  674. }
  675. for(; i < counttag; i ++)
  676. {
  677. NSDictionary *dict = [newArrayList objectAtIndex:i];
  678. GiftModel * giftModel = [GiftModel mj_objectWithKeyValues:dict];
  679. GiftSubView *giftSubView = [[GiftSubView alloc]initWithFrame:CGRectMake(btn_x_2, btn_y_2, (giftListContrainerView.frame.size.width+2)/kGiftHorizontalNum, (giftListContrainerView.frame.size.height+2)/_giftVerticalNum)];
  680. giftSubView.luckBtn.hidden = YES;
  681. /*if(giftModel.is_bag == 1)
  682. {
  683. giftSubView.labNumber.height = 15;
  684. giftSubView.labNumber.hidden = NO;
  685. giftSubView.labNumber.text = [NSString stringWithFormat:@"x%@",giftModel.giftnum];
  686. giftSubView.diamondsLabel.y += 15;
  687. giftSubView.diamondsImgView.y += 15;
  688. }
  689. else
  690. {
  691. giftSubView.labNumber.height = 0;
  692. giftSubView.labNumber.hidden = YES;
  693. }*/
  694. if (giftModel.is_lucky == 1 || giftModel.is_animated == 1) {
  695. giftSubView.luckBtn.hidden = NO;
  696. }
  697. [giftSubView.luckBtn setTitle:giftModel.is_animated == 1 ? ASLocalizedString(@"动效"): ASLocalizedString(@"幸运") forState:UIControlStateNormal];
  698. [giftSubView.luckBtn setBackgroundImage:[UIImage imageNamed:giftModel.is_animated == 1 ? @"bogo_gift_list_lucky_gif": @"bogo_gift_list_lucky"] forState:UIControlStateNormal];
  699. /*if(giftModel.max_silver_coin > 0)
  700. {
  701. [giftSubView.luckBtn setTitle:ASLocalizedString(@"银币") forState:UIControlStateNormal];
  702. giftSubView.luckBtn.hidden = NO;
  703. [giftSubView.luckBtn setBackgroundImage:[UIImage imageNamed:@"bogo_gift_list_lucky"] forState:UIControlStateNormal];
  704. // giftSubView.diamondsImgView.image = [UIImage imageNamed:@"6银币"];
  705. }*/
  706. giftSubView.delegate = self;
  707. giftSubView.tag = i;
  708. giftSubView.index_x = index;
  709. giftSubView.index_y = i;
  710. giftSubView.txtLabel.text = giftModel.name;
  711. giftSubView.diamondsLabel.text = [NSString stringWithFormat:@"%ld",(long)giftModel.diamonds];
  712. [giftSubView.imgView sd_setImageWithURL:[NSURL URLWithString:giftModel.icon] placeholderImage:kDefaultPreloadImgSquare];
  713. [giftSubView resetDiamondsFrame];
  714. UIButton *colorCoin = [[UIButton alloc] init];
  715. [colorCoin setTitle:ASLocalizedString(@"彩钻")forState:UIControlStateNormal];
  716. colorCoin.frame = CGRectMake(3, 3, 20, 15);
  717. colorCoin.titleLabel.font = [UIFont systemFontOfSize:8];
  718. [colorCoin setTitleColor:kWhiteColor forState:UIControlStateNormal];
  719. colorCoin.layer.cornerRadius = 3;
  720. colorCoin.layer.borderColor = kWhiteColor.CGColor;
  721. colorCoin.layer.masksToBounds = YES;
  722. colorCoin.layer.borderWidth = 1;
  723. [giftSubView addSubview:colorCoin];
  724. if([giftModel.type isEqualToString:@"1"])
  725. {
  726. colorCoin.hidden = NO;
  727. }
  728. else
  729. {
  730. colorCoin.hidden = YES;
  731. }
  732. colorCoin.hidden = YES;
  733. if (giftModel.is_much == 1)
  734. {
  735. [giftSubView.continueImgView setImage:[UIImage imageNamed:@"lr_gift_list_continue"]];
  736. }
  737. else
  738. {
  739. [giftSubView.continueImgView setImage:[UIImage imageNamed:@""]];
  740. }
  741. [giftListContrainerView addSubview:giftSubView];
  742. [itemSubArray addObject:giftSubView];
  743. //计算下一个按钮的位置
  744. if (i < [newArrayList count]-1)
  745. { //判断是否有下一个按钮
  746. //列
  747. if (giftSubView.frame.origin.x + giftSubView.frame.size.width >= self.frame.size.width)
  748. {
  749. //换行
  750. btn_x_2 = -1;
  751. btn_y_2 = giftSubView.frame.origin.y + giftSubView.frame.size.height;
  752. }
  753. else
  754. {
  755. btn_x_2 = giftSubView.frame.origin.x + giftSubView.frame.size.width;
  756. }
  757. }
  758. }
  759. // if (num == 1)
  760. // {
  761. // [self addSubview:bottomView];
  762. // }
  763. // else
  764. // {
  765. // [_bottomViewArray addObject:bottomView];
  766. // }
  767. [_bottomViewArray addObject:bottomView];
  768. }
  769. [_itemArray addObject:itemSubArray];
  770. if ([_bottomViewArray count]>0)
  771. {
  772. // int offset = 0;
  773. // if(self.isVoice)
  774. // {
  775. // offset = 44;
  776. // }
  777. // SDCycleScrollView2 *cycleScrollView = [SDCycleScrollView2 cycleScrollViewWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height-kSendGiftContrainerHeight - 30 - offset) imagesGroup:_bottomViewArray];
  778. SDCycleScrollView2 *cycleScrollView = [SDCycleScrollView2 cycleScrollViewWithFrame:CGRectMake(0, 0, self.frame.size.width, scrollView.height) imagesGroup:_bottomViewArray];
  779. cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
  780. cycleScrollView.pageControlDotSize = CGSizeMake(kAdvsPageWidth, kAdvsPageWidth);
  781. cycleScrollView.autoScrollTimeInterval = 0;
  782. cycleScrollView.dotColor = kWhiteColor;
  783. cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
  784. cycleScrollView.left = index*self.scrollView.width;
  785. [scrollView addSubview:cycleScrollView];
  786. NSLog(@"");
  787. }
  788. }
  789. }
  790. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  791. RoomUserInfo *info = self.newUserArray[indexPath.item];
  792. for (int i=0; i<self.newUserArray.count; i++) {
  793. ((RoomUserInfo *)(self.newUserArray[i])).selected = NO;
  794. }
  795. info.selected = YES;
  796. [GlobalVariables sharedInstance].giftSelecUserId = info.user_id;
  797. [collectionView reloadData];
  798. }
  799. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
  800. NSLog(@"scrollViewDidEndDecelerating :%f",scrollView.contentOffset.x);
  801. NSInteger index = scrollView.contentOffset.x/self.scrollView.width;
  802. [self.topView resetIndexs:index];
  803. // .indexs = index;
  804. // [self.topView setIndex:index];
  805. }
  806. #pragma mark GiftSubViewDelegate
  807. - (void)cateBtn:(int)indexTag index_x:(NSInteger)index_x index_y:(NSInteger)index_y
  808. {
  809. NSLog(@"indexTag:%ld index_x:%ld index_y:%ld",indexTag,index_x,index_y);
  810. GiftModel *giftModel = _giftMArray[index_x][index_y];
  811. for (int i=0; i<[_itemArray count]; i++)
  812. {
  813. NSArray *tempArray = _itemArray[i];
  814. for (NSInteger j = 0; j < tempArray.count; j++) {
  815. UIView *view = [tempArray objectAtIndex:j];
  816. if ([view isKindOfClass:[GiftSubView class]])
  817. {
  818. GiftSubView *giftSubView = (GiftSubView *)view;
  819. if (giftSubView.index_x == index_x && giftSubView.index_y == index_y)
  820. {
  821. if (giftModel.isSelected)
  822. {
  823. [_sendBtn setBackgroundColor:[UIColor lightGrayColor]];
  824. giftModel.isSelected = NO;
  825. giftSubView.bottomBtn.layer.borderWidth = 0.5;
  826. giftSubView.bottomBtn.layer.borderColor = [[UIColor colorWithHexString:@"#ffffff"] colorWithAlphaComponent:0.6].CGColor;
  827. self.selectGiftView = nil;
  828. }
  829. else
  830. {
  831. [_sendBtn setBackgroundColor:kBlackColor];
  832. giftModel.isSelected = YES;
  833. giftSubView.bottomBtn.layer.borderWidth = 2;
  834. giftSubView.bottomBtn.layer.borderColor = [UIColor colorWithHexString:@"#C28CF8"].CGColor;
  835. giftSubView.bottomBtn.layer.cornerRadius = 5;
  836. self.selectGiftView = giftSubView;
  837. }
  838. }
  839. else
  840. {
  841. GiftModel *giftModel2 = _giftMArray[giftSubView.index_x][giftSubView.index_y];
  842. if (giftModel2.isSelected)
  843. {
  844. giftModel2.isSelected = NO;
  845. giftSubView.bottomBtn.layer.borderWidth = 0.5;
  846. giftSubView.bottomBtn.layer.borderColor = [[UIColor colorWithHexString:@"#ffffff"] colorWithAlphaComponent:0.6].CGColor;
  847. self.selectGiftView = nil;
  848. }
  849. }
  850. }
  851. }
  852. }
  853. if (_upSelectedIndex != indexTag) {
  854. _sendedTime = 0;
  855. }
  856. _upSelectedIndex = indexTag;
  857. }
  858. - (void)senBtnEnabled:(UIButton *)btn
  859. {
  860. if (btn == _sendBtn)
  861. {
  862. _sendBtn.userInteractionEnabled = YES;
  863. }
  864. else if(btn == _continueBtn)
  865. {
  866. _continueBtn.userInteractionEnabled = YES;
  867. }
  868. }
  869. - (void)setNumAction:(id)sender{
  870. [self.popView showWithAnimated:YES];
  871. }
  872. - (QMUIPopupMenuView *)popView{
  873. if (!_popView) {
  874. _popView = [[QMUIPopupMenuView alloc] init];
  875. _popView.borderWidth = 0;
  876. _popView.automaticallyHidesWhenUserTap = YES;// 点击空白地方消失浮层
  877. _popView.shouldShowItemSeparator = YES;
  878. _popView.backgroundColor = [UIColor qmui_colorWithHexString:@"#7F000000"];
  879. _popView.itemConfigurationHandler = ^(QMUIPopupMenuView *aMenuView, QMUIPopupMenuButtonItem *aItem, NSInteger section, NSInteger index) {
  880. // 利用 itemConfigurationHandler 批量设置所有 item 的样式
  881. [aItem.button setTitleColor:[UIColor qmui_colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
  882. [aItem.button setBackgroundColor:[UIColor qmui_colorWithHexString:@"#7F000000"]];
  883. aItem.button.titleLabel.font = [UIFont systemFontOfSize:14];
  884. };
  885. NSMutableArray *itemArr = [NSMutableArray array];
  886. for (int i =0 ; i<[GlobalVariables sharedInstance].giftQuantityModelList.count; i++) {
  887. GiftQuantityModel *model = [GlobalVariables sharedInstance].giftQuantityModelList[i];
  888. __weak __typeof(self)weakSelf = self;
  889. QMUIPopupMenuButtonItem *qmuiItem = [QMUIPopupMenuButtonItem itemWithImage:nil title:model.title handler:^(QMUIPopupMenuButtonItem *aItem) {
  890. weakSelf.numberModel = [GlobalVariables sharedInstance].giftQuantityModelList[i];
  891. [weakSelf resetNumber];
  892. [self.popView hideWithAnimated:NO];
  893. }];
  894. [qmuiItem qmui_bindObject:model forKey:@"model"];
  895. [itemArr addObject:qmuiItem];
  896. }
  897. _popView.items = itemArr;
  898. _popView.sourceView = self.numberBtn;// 相对于 button4 布局
  899. }
  900. return _popView;
  901. }
  902. #pragma mark 点击发送按钮
  903. - (void)senGiftAction:(id)sender
  904. {
  905. UIButton *sendBtn = (UIButton *)sender;
  906. if (sendBtn == _sendBtn)
  907. {
  908. // _sendBtn.userInteractionEnabled = NO;
  909. }
  910. else if(sendBtn == _continueBtn)
  911. {
  912. // _continueBtn.userInteractionEnabled = NO;
  913. }
  914. // [self performSelector:@selector(senBtnEnabled:) withObject:sendBtn afterDelay:0.3];
  915. _selectedGiftTime = [_decTimeCLabel.text integerValue];
  916. if (_selectedGiftTime == 0)
  917. {
  918. _sendedTime = 0;
  919. }
  920. [self bringSubviewToFront:_continueContainerView];
  921. BOOL haveSelected = NO;
  922. for (int i=0; i<[_itemArray count]; i++)
  923. {
  924. NSArray *tempArray = _itemArray[i];
  925. for (NSInteger j = 0; j < tempArray.count; j ++) {
  926. GiftModel *giftModel = _giftMArray[i][j];
  927. if (giftModel.isSelected)
  928. {
  929. UserModel *model = [GlobalVariables sharedInstance].userModel;
  930. // [GlobalVariables sharedInstance].u
  931. //
  932. NSLog(@"GlobalVariables sharedInstance].is_guart%@",[GlobalVariables sharedInstance].is_guartian);
  933. /*if ([giftModel.type isEqualToString:@"2"] &&
  934. [GlobalVariables sharedInstance].is_guartian.intValue != 1) {
  935. [FanweMessage alertHUD:@"守护专属~您尚未开通守护"];
  936. return;
  937. }*/
  938. if ([giftModel.type isEqualToString:@"3"] && model.is_vip.intValue == 0) {
  939. [self showVipRecharge];
  940. return;
  941. }
  942. if ([giftModel.type isEqualToString:@"4"] && model.noble_vip_type.intValue == 0) {
  943. [self showNobleNobleVIP];
  944. return;
  945. }
  946. // if(!giftModel.is_bag)
  947. // {
  948. if ((([[IMAPlatform sharedInstance].host getDiamonds] < giftModel.diamonds) && ![giftModel.type isEqualToString:@"1"]) && (([[IMAPlatform sharedInstance].host.colorful intValue] < giftModel.diamonds) && [giftModel.type isEqualToString:@"1"]))
  949. {
  950. [FanweMessage alert:[NSString stringWithFormat:ASLocalizedString(@"当前%@不足"),self.BuguLive.appModel.diamond_name]];
  951. [[IMAPlatform sharedInstance].host getMyInfo:nil];
  952. return;
  953. }
  954. // }
  955. //如果是贵族专属礼物
  956. // if ([giftModel.type isEqualToString:@"2"]) {
  957. // //需要判断当前是不是有贵族礼物特权
  958. // if (self.userPageModel.noble_gift.integerValue != 1) {
  959. // [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"您当前没有贵族礼物特权,无法发送贵族专属礼物")];
  960. // return;
  961. // }
  962. // }
  963. haveSelected = YES;
  964. if (_delegate && [_delegate respondsToSelector:@selector(senGift:AndGiftModel:)])
  965. {
  966. if (_currentGiftModel == giftModel)
  967. {
  968. // 判断这个礼物是否可以连发
  969. if (giftModel.is_much && _selectedGiftTime>0)
  970. {
  971. giftModel.is_plus = 1;
  972. }
  973. else
  974. {
  975. giftModel.is_plus = 0;
  976. }
  977. }
  978. else
  979. {
  980. giftModel.is_plus = 0;
  981. _currentGiftModel = giftModel;
  982. }
  983. if (giftModel.is_much)
  984. {
  985. _sendBtn.hidden = YES;
  986. _continueContainerView.hidden = NO;
  987. [_decTimeCLabel countFrom:(NSInteger)kGiftViewSendedDescTime*10 to:0 withDuration:(NSInteger)kGiftViewSendedDescTime];
  988. __weak GiftView* blockSelf = self;
  989. _decTimeCLabel.completionBlock = ^{
  990. [blockSelf finishContinue];
  991. };
  992. _sendedTime ++;
  993. _sendedTimeLabel.text = [NSString stringWithFormat:@"X%ld",(long)_sendedTime];
  994. }
  995. else
  996. {
  997. _sendBtn.hidden = NO;
  998. _continueContainerView.hidden = YES;
  999. }
  1000. giftModel.num = self.numberModel.num;
  1001. [_delegate senGift:self AndGiftModel:giftModel];
  1002. }
  1003. }
  1004. }
  1005. }
  1006. if (!haveSelected)
  1007. {
  1008. [FanweMessage alert:ASLocalizedString(@"还没选择礼物哦")];
  1009. }
  1010. }
  1011. -(void)showVipRecharge{
  1012. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:ASLocalizedString(@"您当前未开通VIP,需要开通后才能发送此礼物")preferredStyle:UIAlertControllerStyleAlert];
  1013. UIAlertAction *actionCacel = [UIAlertAction actionWithTitle:ASLocalizedString(@"取消")style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1014. }];
  1015. UIAlertAction *actionConfirm = [UIAlertAction actionWithTitle:ASLocalizedString(@"确定")style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1016. NSString *tmpUrlStr = [GlobalVariables sharedInstance].appModel.h5_url.shop_url;
  1017. BGMainWebViewController *tmpController = [BGMainWebViewController webControlerWithUrlStr:tmpUrlStr isShowIndicator:YES isShowNavBar:YES isShowBackBtn:YES];
  1018. // tmpController.navTitleStr = ASLocalizedString(@"座驾");
  1019. [[AppDelegate sharedAppDelegate] pushViewController:tmpController animated:YES];
  1020. }];
  1021. [alertController addAction:actionCacel];
  1022. [alertController addAction:actionConfirm];
  1023. [[AppDelegate sharedAppDelegate].topViewController presentViewController:alertController animated:YES completion:nil];
  1024. }
  1025. //贵族
  1026. -(void)showNobleNobleVIP{
  1027. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:ASLocalizedString(@"您当前未开通贵族,需要开通后才能发送此礼物")preferredStyle:UIAlertControllerStyleAlert];
  1028. UIAlertAction *actionCacel = [UIAlertAction actionWithTitle:ASLocalizedString(@"取消")style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1029. }];
  1030. UIAlertAction *actionConfirm = [UIAlertAction actionWithTitle:ASLocalizedString(@"确定")style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1031. BogoNobleViewController *vc = [BogoNobleViewController new];
  1032. [[AppDelegate sharedAppDelegate] pushViewController:vc animated:YES];
  1033. }];
  1034. [alertController addAction:actionCacel];
  1035. [alertController addAction:actionConfirm];
  1036. [[AppDelegate sharedAppDelegate].topViewController presentViewController:alertController animated:YES completion:nil];
  1037. }
  1038. - (UICollectionView *)peopleCollectionView{
  1039. if (!_peopleCollectionView) {
  1040. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  1041. layout.itemSize = CGSizeMake(30,30);
  1042. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  1043. layout.minimumLineSpacing = 5;
  1044. layout.minimumInteritemSpacing = 20;
  1045. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  1046. _peopleCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout];
  1047. _peopleCollectionView.delegate = self;
  1048. _peopleCollectionView.dataSource = self;
  1049. _peopleCollectionView.pagingEnabled = YES;
  1050. _peopleCollectionView.showsHorizontalScrollIndicator = NO;
  1051. [_peopleCollectionView registerNib:[UINib nibWithNibName:NSStringFromClass([BogoLiveGiftViewPeopleCell class]) bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:NSStringFromClass([BogoLiveGiftViewPeopleCell class])];
  1052. _peopleCollectionView.backgroundColor = kClearColor;
  1053. }
  1054. return _peopleCollectionView;
  1055. }
  1056. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  1057. return 1;
  1058. }
  1059. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  1060. return self.newUserArray.count;
  1061. }
  1062. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  1063. BogoLiveGiftViewPeopleCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([BogoLiveGiftViewPeopleCell class]) forIndexPath:indexPath];
  1064. [cell setDataArray:self.newUserArray];
  1065. RoomUserInfo *info = self.newUserArray[indexPath.item];
  1066. // if (info.user_id) {
  1067. [cell setUser:info];
  1068. // }
  1069. return cell;
  1070. }
  1071. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  1072. return CGSizeMake(30, 30);
  1073. }
  1074. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  1075. return 3;
  1076. }
  1077. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  1078. return 15;
  1079. }
  1080. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
  1081. return UIEdgeInsetsMake(0, 5, 0, 0);
  1082. }
  1083. - (NSMutableArray *)newUserArray{
  1084. if (!_newUserArray) {
  1085. _newUserArray = [NSMutableArray array];
  1086. }
  1087. return _newUserArray;
  1088. }
  1089. @end