TCShowLiveBottomView.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  1. //
  2. // TCShowLiveBottomView.m
  3. // TCShow
  4. //
  5. // Created by AlexiChen on 16/4/14.
  6. // Copyright © 2016年 AlexiChen. All rights reserved.
  7. //
  8. #import "TCShowLiveBottomView.h"
  9. #import "UIView+CustomAutoLayout.h"
  10. @implementation TCShowLiveBottomView
  11. #pragma mark - ----------------------- 直播生命周期 -----------------------
  12. - (void)releaseAll
  13. {
  14. [[NSNotificationCenter defaultCenter] removeObserver:self];
  15. [self.bjsbadge removeFromSuperview];
  16. [self.jsbadge removeFromSuperview];
  17. }
  18. - (void)dealloc
  19. {
  20. [self releaseAll];
  21. }
  22. #pragma mark 开始直播
  23. - (void)startLive
  24. {
  25. }
  26. #pragma mark 暂停直播
  27. - (void)pauseLive
  28. {
  29. }
  30. #pragma mark 重新开始直播
  31. - (void)resumeLive
  32. {
  33. }
  34. #pragma mark 结束直播
  35. - (void)endLive
  36. {
  37. [self releaseAll];
  38. }
  39. #pragma mark - ----------------------- 其他 -----------------------
  40. - (instancetype)initWithFrame:(CGRect)frame
  41. {
  42. if (self = [super initWithFrame:frame])
  43. {
  44. #if kSupportIMMsgCache
  45. // 创建点赞消息缓存
  46. self.praiseImageCache = [NSMutableArray array];
  47. // 预先缓存点赞动画图片,主要是防止在收到大量点赞消息时,因加载资源的耗时
  48. /**
  49. UIImage *img = [UIImage imageNamed:@"img_like"];
  50. [self.praiseImageCache addObject:[img imageWithTintColor:[UIColor flatRedColor]]];
  51. [self.praiseImageCache addObject:[img imageWithTintColor:[UIColor flatDarkRedColor]]];
  52. */
  53. [self.praiseImageCache addObject:[UIImage imageNamed:@"heart0"]];
  54. [self.praiseImageCache addObject:[UIImage imageNamed:@"heart1"]];
  55. [self.praiseImageCache addObject:[UIImage imageNamed:@"heart2"]];
  56. [self.praiseImageCache addObject:[UIImage imageNamed:@"heart3"]];
  57. [self.praiseImageCache addObject:[UIImage imageNamed:@"heart4"]];
  58. [self.praiseImageCache addObject:[UIImage imageNamed:@"heart5"]];
  59. [self.praiseImageCache addObject:[UIImage imageNamed:@"heart6"]];
  60. self.praiseAnimationCache = [NSMutableArray array];
  61. #endif
  62. _canSendLightMsg = YES;
  63. _showFuncs = [NSMutableArray array];
  64. _menusBottomView = [[UIView alloc]init];
  65. _menusBottomView.backgroundColor = kClearColor;
  66. [self addSubview:_menusBottomView];
  67. //发送消息按钮
  68. FWWeakify(self)
  69. // _msgMenuBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"lr_bottom_comment"] action:^(id<MenuAbleItem> menu) {
  70. // FWStrongify(self)
  71. // [self menuButtonAction:menu];
  72. // }];
  73. _msgMenuBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"lr_bottom_comment"] action:^(id<MenuAbleItem> menu){
  74. FWStrongify(self)
  75. [self menuButtonAction:menu];
  76. }];
  77. _msgMenuBtn.tag = EFunc_INPUT;
  78. [_msgMenuBtn setImage:[UIImage imageNamed:@"lr_bottom_comment"] forState:UIControlStateHighlighted];
  79. /**
  80. // 购物
  81. if ([self.BuguLive.appModel.shopping_goods integerValue] == 1 || self.BuguLive.appModel.open_podcast_goods == 1) {
  82. _starShopBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"fw_liveRoom_tools"] action:^(id<MenuAbleItem> menu) {
  83. [ws menuButtonAction:menu];
  84. }];
  85. _starShopBtn.tag = EFunc_STARSHOP ;
  86. _starShopBtn.hidden = YES;
  87. [_starShopBtn setImage:[UIImage imageNamed:@"fw_liveRoom_tools"] forState:UIControlStateHighlighted];
  88. }
  89. */
  90. // 更多功能
  91. if ([self.BuguLive.appModel.shopping_goods integerValue] == 1 || self.BuguLive.appModel.open_podcast_goods == 1)
  92. {
  93. _moreToolsBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"lr_bottom_tools"] action:^(id<MenuAbleItem> menu) {
  94. FWStrongify(self)
  95. [self menuButtonAction:menu];
  96. }];
  97. _moreToolsBtn.tag = EFunc_MORETOOLS;
  98. _moreToolsBtn.hidden = YES;
  99. [_moreToolsBtn setImage:[UIImage imageNamed:@"lr_bottom_tools"] forState:UIControlStateHighlighted];
  100. }
  101. // 插件中心
  102. _gamesBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"lr_bottom_tools"] action:^(id<MenuAbleItem> menu) {
  103. FWStrongify(self)
  104. [self menuButtonAction:menu];
  105. }];
  106. _gamesBtn.tag = EFunc_GAMES ;
  107. [_gamesBtn setImage:[UIImage imageNamed:@"lr_bottom_tools"] forState:UIControlStateHighlighted];
  108. _gamesBtn.hidden = YES;
  109. // 开始游戏
  110. _beginGameBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"gm_game_licensing"] action:^(id<MenuAbleItem> menu) {
  111. FWStrongify(self)
  112. [self menuButtonAction:menu];
  113. }];
  114. _beginGameBtn.tag = EFunc_BEGINGAMES;
  115. _beginGameBtn.hidden = YES;
  116. [_beginGameBtn setImage:[UIImage imageNamed:@"gm_game_licensing"] forState:UIControlStateHighlighted];
  117. //游戏视图显示与隐藏开关
  118. _switchGameViewBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"gm_game_closeView"] action:^(id<MenuAbleItem> menu) {
  119. FWStrongify(self)
  120. [self menuButtonAction:menu];
  121. }];
  122. _switchGameViewBtn.tag = EFunc_SWITCHGAMEVIEW;
  123. _switchGameViewBtn.hidden = YES;
  124. [_switchGameViewBtn setImage:[UIImage imageNamed:@"gm_game_closeView"] forState:UIControlStateHighlighted];
  125. if(self.BuguLive.appModel.open_banker_module == 1)
  126. {
  127. _switchBankerBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"gm_open_banker"] action:^(id<MenuAbleItem> menu) {
  128. FWStrongify(self)
  129. [self menuButtonAction:menu];
  130. }];
  131. _switchBankerBtn.tag = EFunc_SWITCH_BANNER;
  132. _switchBankerBtn.hidden = YES;
  133. [_switchBankerBtn setImage:[UIImage imageNamed:@"gm_open_banker"] forState:UIControlStateHighlighted];
  134. _grabBankerBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"gm_grab_banker"] action:^(id<MenuAbleItem> menu) {
  135. FWStrongify(self)
  136. [self menuButtonAction:menu];
  137. }];
  138. _grabBankerBtn.tag = EFunc_GRAB_BANNER;
  139. _grabBankerBtn.hidden = YES;
  140. [_grabBankerBtn setImage:[UIImage imageNamed:@"gm_grab_banker"] forState:UIControlStateHighlighted];
  141. }
  142. //这个后期 统一处理 不写成通知
  143. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(newMsgNotification:) name:@"reloadunread" object:nil];
  144. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(newMsgNotification:) name:g_notif_chatmsg object:nil];
  145. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(newMsgNotification:) name:@"imRemoveNeedUpdate" object:nil];
  146. }
  147. return self;
  148. }
  149. - (void)refreshLiveItem:(id<FWShowLiveRoomAble>)liveItem liveInfo:(CurrentLiveInfo *)liveInfo
  150. {
  151. _liveInfo = liveInfo;
  152. [self addLiveFunc:[liveItem liveType]];
  153. }
  154. #pragma mark 主播需要添加的按钮
  155. - (void)hostAddFunc
  156. {
  157. if (SUS_WINDOW.isShowLivePay == YES)
  158. {
  159. [self addFunc:EFunc_LIVEPAY];
  160. }
  161. if (SUS_WINDOW.isShowMention == YES)
  162. {
  163. [self addFunc:EFunc_MENTION];
  164. }
  165. if ([[GlobalVariables sharedInstance].appModel.is_open_shop isEqualToString:@"1"]) {
  166. [self addFunc:EFunc_SHOP];
  167. }
  168. self.shopBtn.hidden = ![GlobalVariables sharedInstance].isShop;
  169. [self addFunc:EFunc_WISH];
  170. [self addFunc:EFunc_CHART];
  171. // 非私密直播才能加分享按钮
  172. if (![_liveInfo.is_private isEqualToString:@"1"])
  173. {
  174. [self addFunc:EFunc_SHARE];
  175. }
  176. if (_liveInfo.push_type.integerValue == 1) {
  177. [self addFunc:EFunc_PK];
  178. }
  179. [self addFunc:EFunc_CLOSE];
  180. }
  181. #pragma mark 观众需要添加的按钮
  182. - (void)audienceAddFunc
  183. {
  184. if ([[GlobalVariables sharedInstance].appModel.is_open_shop isEqualToString:@"1"]) {
  185. [self addFunc:EFunc_SHOP];
  186. }
  187. self.shopBtn.hidden = ![GlobalVariables sharedInstance].isShop;
  188. if (_liveInfo.create_type == 1)
  189. {
  190. [self addFunc:EFunc_FULL_SCREEN];
  191. }
  192. #if kSupportH5Shopping
  193. if([AppDelegate sharedAppDelegate].sus_window.rootViewController)
  194. {// 只有悬浮做缩放
  195. [self addFunc:EFunc_SALES_SUSWINDOW];// 非 自己直播 缩放
  196. }
  197. #endif
  198. [self addFunc:EFunc_VOICE_GAME];
  199. [self addFunc:EFunc_CHART];
  200. [self addFunc:EFunc_RED_PACK];
  201. if (_liveInfo.has_lianmai && _liveInfo.push_type.integerValue == 1)
  202. {
  203. [self addFunc:EFunc_CONNECT_MIKE];
  204. }
  205. [self addFunc:EFunc_GIFT];
  206. // 非私密直播才能加分享按钮
  207. if (![_liveInfo.is_private isEqualToString:@"1"])
  208. {
  209. [self addFunc:EFunc_SHARE];
  210. }
  211. [self addFunc:EFunc_CLOSE];
  212. }
  213. #pragma mark 添加菜单
  214. - (void)addLiveFunc:(NSInteger)liveType
  215. {
  216. if (_menusBottomView)
  217. {
  218. [_menusBottomView removeFromSuperview];
  219. _menusBottomView = nil;
  220. _menusBottomView = [[UIView alloc]init];
  221. _menusBottomView.backgroundColor = kClearColor;
  222. [self addSubview:_menusBottomView];
  223. [_showFuncs removeAllObjects];
  224. }
  225. if (liveType == FW_LIVE_TYPE_HOST)
  226. {
  227. [_moreToolsBtn removeFromSuperview];
  228. _moreToolsBtn = nil;
  229. _gamesBtn.hidden = NO;
  230. [self hostAddFunc];
  231. }
  232. else if (liveType == FW_LIVE_TYPE_AUDIENCE)
  233. {
  234. _moreToolsBtn.hidden = NO;
  235. _gamesBtn.hidden = YES;
  236. [self audienceAddFunc];
  237. }
  238. [self relayoutFrameOfSubViews];
  239. }
  240. - (void)addFunc:(NSInteger)funcid
  241. {
  242. MenuButton *menuBtn = nil;
  243. FWWeakify(self)
  244. switch (funcid)
  245. {
  246. case EFunc_VOICE_GAME:
  247. {
  248. menuBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"游戏底部"] action:^(id<MenuAbleItem> menu) {
  249. FWStrongify(self)
  250. [self menuButtonAction:menu];
  251. }];
  252. [menuBtn setImage:[UIImage imageNamed:@"lr_bottom_gift_list"] forState:UIControlStateSelected];
  253. }
  254. break;
  255. case EFunc_RED_PACK:
  256. {
  257. menuBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"hongbao1"] action:^(id<MenuAbleItem> menu) {
  258. FWStrongify(self)
  259. [self menuButtonAction:menu];
  260. }];
  261. [menuBtn setImage:[UIImage imageNamed:@"hongbao1"] forState:UIControlStateSelected];
  262. }
  263. break;
  264. case EFunc_GIFT:
  265. {
  266. menuBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"lr_bottom_gift_list"] action:^(id<MenuAbleItem> menu) {
  267. FWStrongify(self)
  268. [self menuButtonAction:menu];
  269. }];
  270. [menuBtn setImage:[UIImage imageNamed:@"lr_bottom_gift_list"] forState:UIControlStateSelected];
  271. }
  272. break;
  273. case EFunc_CONNECT_MIKE:
  274. {
  275. menuBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"lr_bottom_connect_mick"] action:^(id<MenuAbleItem> menu) {
  276. FWStrongify(self)
  277. [self menuButtonAction:menu];
  278. }];
  279. [menuBtn setImage:[UIImage imageNamed:@"lr_bottom_connect_mick"] forState:UIControlStateSelected];
  280. }
  281. break;
  282. case EFunc_SHARE:
  283. {
  284. menuBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"lr_bottom_share"] action:^(id<MenuAbleItem> menu) {
  285. FWStrongify(self)
  286. [self menuButtonAction:menu];
  287. }];
  288. [menuBtn setImage:[UIImage imageNamed:@"lr_bottom_share"] forState:UIControlStateSelected];
  289. }
  290. break;
  291. case EFunc_CHART:
  292. {
  293. menuBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"lr_bottom_private_msg"] action:^(id<MenuAbleItem> menu) {
  294. FWStrongify(self)
  295. [self menuButtonAction:menu];
  296. }];
  297. [menuBtn setImage:[UIImage imageNamed:@"lr_bottom_private_msg"] forState:UIControlStateSelected];
  298. menuBtn.tag = EFunc_CHART;
  299. [self performSelector:@selector(addMsgBadge:) withObject:menuBtn afterDelay:2];
  300. }
  301. break;
  302. case EFunc_SALES_SUSWINDOW: //非自己直播 缩放window btn
  303. {
  304. menuBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"ic_live_bottom_saleWindowBtn"] action:^(id<MenuAbleItem> menu) {
  305. FWStrongify(self)
  306. [self menuButtonAction:menu];
  307. }];
  308. break;
  309. }
  310. case EFunc_LIVEPAY: //付费按钮
  311. {
  312. menuBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"lr_bottom_changepay"] action:^(id<MenuAbleItem> menu) {
  313. FWStrongify(self)
  314. [self menuButtonAction:menu];
  315. }];
  316. [menuBtn setImage:[UIImage imageNamed:@"lr_bottom_changepay "] forState:UIControlStateSelected];
  317. break;
  318. }
  319. case EFunc_MENTION: //提档
  320. {
  321. menuBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"lr_bottom_mention"] action:^(id<MenuAbleItem> menu) {
  322. FWStrongify(self)
  323. [self menuButtonAction:menu];
  324. }];
  325. [menuBtn setImage:[UIImage imageNamed:@"lr_bottom_mention"] forState:UIControlStateSelected];
  326. break;
  327. }
  328. case EFunc_FULL_SCREEN: // 全屏
  329. {
  330. menuBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"lr_bottom_full_screen"] action:^(id<MenuAbleItem> menu) {
  331. FWStrongify(self)
  332. [self menuButtonAction:menu];
  333. }];
  334. [menuBtn setImage:[UIImage imageNamed:@"lr_bottom_full_screen"] forState:UIControlStateSelected];
  335. }
  336. break;
  337. case EFunc_PK: // PK
  338. {
  339. menuBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"PK2"] action:^(id<MenuAbleItem> menu) {
  340. FWStrongify(self)
  341. [self menuButtonAction:menu];
  342. }];
  343. [menuBtn setImage:[UIImage imageNamed:@"PK2"] forState:UIControlStateSelected];
  344. }
  345. break;
  346. case EFunc_SHOP: // 购物车
  347. {
  348. menuBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"lr_bottom_shop"] action:^(id<MenuAbleItem> menu) {
  349. FWStrongify(self)
  350. [self menuButtonAction:menu];
  351. }];
  352. [menuBtn setImage:[UIImage imageNamed:@"lr_bottom_shop"] forState:UIControlStateSelected];
  353. _shopBtn = menuBtn;
  354. }
  355. break;
  356. case EFunc_WISH: // 心愿单
  357. {
  358. menuBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"lr_bottom_wish"] action:^(id<MenuAbleItem> menu) {
  359. FWStrongify(self)
  360. [self menuButtonAction:menu];
  361. }];
  362. [menuBtn setImage:[UIImage imageNamed:@"lr_bottom_wish"] forState:UIControlStateSelected];
  363. }
  364. break;
  365. case EFunc_CLOSE: // 购物车
  366. {
  367. menuBtn = [[MenuButton alloc] initWithTitle:nil icon:[UIImage imageNamed:@"lr_bottom_close"] action:^(id<MenuAbleItem> menu) {
  368. FWStrongify(self)
  369. [self menuButtonAction:menu];
  370. }];
  371. [menuBtn setImage:[UIImage imageNamed:@"lr_bottom_close"] forState:UIControlStateSelected];
  372. // _shopBtn = menuBtn;
  373. }
  374. break;
  375. default:
  376. break;
  377. }
  378. if (menuBtn)
  379. {
  380. menuBtn.tag = funcid;
  381. [_menusBottomView addSubview:menuBtn];
  382. [_showFuncs addObject:menuBtn];
  383. }
  384. }
  385. - (void)addMsgBadge:(MenuButton *)menuBtn
  386. {
  387. FWWeakify(self)
  388. [SFriendObj getAllUnReadCountComplete:^(int num) {
  389. FWStrongify(self)
  390. int jj = num;
  391. self.jsbadge = [[JSBadgeView alloc]initWithParentView:menuBtn alignment:JSBadgeViewAlignmentTopRight];
  392. if(jj)
  393. {
  394. if(jj > 98)
  395. {
  396. self.jsbadge.badgeText = @"99+";
  397. }
  398. else
  399. {
  400. self.jsbadge.badgeText = [NSString stringWithFormat:@"%d",jj];
  401. }
  402. }
  403. else
  404. {
  405. self.jsbadge.badgeText = nil;
  406. }
  407. FWWeakify(self)
  408. [self xw_addNotificationForName:@"clearJsbadge" block:^(NSNotification * _Nonnull notification) {
  409. FWStrongify(self)
  410. self.jsbadge.badgeText = nil;
  411. }];
  412. }];
  413. }
  414. - (void)newMsgNotification:(NSNotification*)notifiation
  415. {
  416. [SFriendObj getAllUnReadCountComplete:^(int num) {
  417. if(num)
  418. {
  419. if(num >98)
  420. {
  421. self.jsbadge.badgeText = @"99+";
  422. }
  423. else
  424. {
  425. self.jsbadge.badgeText = [NSString stringWithFormat:@"%d",num];
  426. }
  427. }
  428. else
  429. {
  430. self.jsbadge.badgeText = nil;
  431. }
  432. }];
  433. }
  434. #pragma mark 设置视图frame
  435. - (void)relayoutFrameOfSubViews
  436. {
  437. CGFloat multiple;
  438. if (kScreenW <375 && _showFuncs.count > 4)
  439. {
  440. multiple = 0.3;//间距要缩小要不然 320 显示不下
  441. }
  442. else
  443. {
  444. multiple = 1.0;
  445. }
  446. CGFloat tmpWidth = _showFuncs.count * self.bounds.size.height + multiple*kDefaultMargin * (_showFuncs.count-1);
  447. _menusBottomView.frame = CGRectMake(CGRectGetWidth(self.frame)-tmpWidth-kDefaultMargin, 0, tmpWidth, self.bounds.size.height);
  448. CGRect rect = _menusBottomView.bounds;
  449. rect = CGRectInset(rect, 0, 0);
  450. if (_showFuncs.count)
  451. {
  452. [_menusBottomView alignSubviews:_showFuncs horizontallyWithPadding:kDefaultMargin*multiple margin:0 inRect:rect];
  453. }
  454. //发送消息按钮
  455. _msgMenuBtn.frame = CGRectMake(kDefaultMargin, 0, self.bounds.size.height, self.bounds.size.height);
  456. [self addSubview:_msgMenuBtn];
  457. if ([self.BuguLive.appModel.shopping_goods integerValue] == 1 || self.BuguLive.appModel.open_podcast_goods == 1 )
  458. {
  459. //添加观众端更多工具按钮
  460. [self addSubview:_moreToolsBtn];
  461. _moreToolsBtn.frame = CGRectMake(CGRectGetMaxX(_msgMenuBtn.frame)+kDefaultMargin, 0, self.bounds.size.height, self.bounds.size.height);
  462. }
  463. #if kSupportH5Shopping
  464. _starShopBtn.frame = CGRectMake(2*kDefaultMargin+self.bounds.size.height, 0, 2*self.bounds.size.height, self.bounds.size.height);
  465. [self addSubview:_starShopBtn];
  466. #endif
  467. if (_isHost)
  468. {
  469. _gamesBtn.frame = CGRectMake(CGRectGetMaxX(_msgMenuBtn.frame)+kDefaultMargin, 0, self.bounds.size.height, self.bounds.size.height);
  470. [self addSubview:_gamesBtn];
  471. _beginGameBtn.frame = CGRectMake(CGRectGetMaxX(_gamesBtn.frame)+kDefaultMargin, 0, self.bounds.size.height, self.bounds.size.height);
  472. [self addSubview:_beginGameBtn];
  473. _switchGameViewBtn.frame = CGRectMake(CGRectGetMaxX(_beginGameBtn.frame)+kDefaultMargin, 0, self.bounds.size.height, self.bounds.size.height);
  474. [self addSubview:_switchGameViewBtn];
  475. _switchBankerBtn.frame = CGRectMake(CGRectGetMaxX(_switchGameViewBtn.frame)+kDefaultMargin, 30, self.bounds.size.height, self.bounds.size.height);
  476. [self addSubview:_switchBankerBtn];
  477. if(!self.bjsbadge)
  478. {
  479. self.bjsbadge = [[JSBadgeView alloc]initWithParentView:_switchBankerBtn alignment:JSBadgeViewAlignmentTopRight];
  480. }
  481. if(_bankMessage)
  482. {
  483. self.bjsbadge.badgeText = @"···";
  484. }
  485. else
  486. {
  487. self.bjsbadge.badgeText = nil;
  488. }
  489. }
  490. else
  491. {
  492. if ([self.BuguLive.appModel.shopping_goods integerValue] == 1 || self.BuguLive.appModel.open_podcast_goods == 1)
  493. {
  494. _switchGameViewBtn.frame = CGRectMake(CGRectGetMaxX(_moreToolsBtn.frame)+kDefaultMargin, 0, self.bounds.size.height, self.bounds.size.height);
  495. }
  496. else
  497. {
  498. _switchGameViewBtn.frame = CGRectMake(CGRectGetMaxX(_msgMenuBtn.frame)+kDefaultMargin, 0, self.bounds.size.height, self.bounds.size.height);
  499. }
  500. [self addSubview:_switchGameViewBtn];
  501. _grabBankerBtn.frame = CGRectMake(CGRectGetMaxX(_switchGameViewBtn.frame)+kDefaultMargin, 0, self.bounds.size.height, self.bounds.size.height);
  502. [self addSubview:_grabBankerBtn];
  503. }
  504. }
  505. #pragma mark 按钮点击事件
  506. - (void)menuButtonAction:(MenuButton *)btn
  507. {
  508. if (_delegate && [_delegate respondsToSelector:@selector(onBottomViewClickMenus:fromButton:)])
  509. {
  510. [_delegate onBottomViewClickMenus:self fromButton:btn];
  511. }
  512. }
  513. - (void)onEnableInteractCamera:(MenuButton *)btn
  514. {
  515. if ([_multiDelegate respondsToSelector:@selector(onBottomView:operateCameraOf:fromButton:)])
  516. {
  517. [_multiDelegate onBottomView:self operateCameraOf:_showUser fromButton:btn];
  518. }
  519. }
  520. - (void)onEnableInteractMic:(MenuButton *)btn
  521. {
  522. if ([_multiDelegate respondsToSelector:@selector(onBottomView:operateMicOf:fromButton:)])
  523. {
  524. [_multiDelegate onBottomView:self operateMicOf:_showUser fromButton:btn];
  525. }
  526. }
  527. - (void)onCancelInteract:(MenuButton *)btn
  528. {
  529. if ([_multiDelegate respondsToSelector:@selector(onBottomView:cancelInteractWith:fromButton:)])
  530. {
  531. [_multiDelegate onBottomView:self cancelInteractWith:_showUser fromButton:btn];
  532. }
  533. }
  534. - (void)onSwtichSpeaker:(MenuButton *)btn
  535. {
  536. btn.selected = !btn.selected;
  537. btn.enabled = NO;
  538. }
  539. - (void)showLight
  540. {
  541. if (_canSendLightMsg)
  542. {
  543. _canSendLightMsg = NO;
  544. FWWeakify(self)
  545. // 点赞消息产生的动画,大量产生时非常耗性能,建议观众端不要频繁发送
  546. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  547. FWStrongify(self)
  548. self.canSendLightMsg = YES;
  549. });
  550. }
  551. }
  552. - (void)showLikeHeart
  553. {
  554. // 非纯净模式下显示点赞消息
  555. [self showLikeHeartStartRect:_heartRect];
  556. }
  557. #if kSupportIMMsgCache
  558. - (void)showLikeHeart:(AVIMCache *)cache
  559. {
  560. if (cache.count)
  561. {
  562. // 非纯净模式下显示点赞消息
  563. [self showLikeHeartStartRect:_heartRect count:cache.count > 5 ? 5 : cache.count];
  564. }
  565. else
  566. {
  567. // 没有的时候,释放缓存
  568. if (self.praiseAnimationCache.count)
  569. {
  570. UIImageView *imageView = [self.praiseAnimationCache objectAtIndex:0];
  571. [self.praiseAnimationCache removeObject:imageView];
  572. [imageView removeFromSuperview];
  573. }
  574. }
  575. }
  576. #endif
  577. - (CAAnimation *)hearAnimationFrom:(CGRect)frame
  578. {
  579. //位置
  580. CAKeyframeAnimation *animation=[CAKeyframeAnimation animationWithKeyPath:@"position"];
  581. animation.beginTime = 0.5;
  582. animation.duration = 2.5;
  583. animation.removedOnCompletion = YES;
  584. animation.fillMode = kCAFillModeForwards;
  585. animation.repeatCount= 0;
  586. animation.calculationMode = kCAAnimationCubicPaced;
  587. CGMutablePathRef curvedPath = CGPathCreateMutable();
  588. CGPoint point0 = CGPointMake(frame.origin.x + frame.size.width / 2, frame.origin.y + frame.size.height / 2);
  589. CGPathMoveToPoint(curvedPath, NULL, point0.x, point0.y);
  590. float x11 = point0.x - arc4random() % 30 + 30;
  591. float y11 = frame.origin.y - arc4random() % 60 ;
  592. float x1 = point0.x - arc4random() % 15 + 15;
  593. float y1 = frame.origin.y - arc4random() % 60 - 30;
  594. CGPoint point1 = CGPointMake(x1, y1);
  595. CGPathAddQuadCurveToPoint(curvedPath, NULL, x11, y11, point1.x, point1.y);
  596. int conffset2 = self.superview.bounds.size.width * 0.2;
  597. int conffset21 = self.superview.bounds.size.width * 0.1;
  598. float x2 = point0.x - arc4random() % conffset2 + conffset2;
  599. float y2 = arc4random() % 30 + 240;
  600. float x21 = point0.x - arc4random() % conffset21 + conffset21;
  601. float y21 = (y2 + y1) / 2 + arc4random() % 30 - 30;
  602. CGPoint point2 = CGPointMake(x2, y2);
  603. CGPathAddQuadCurveToPoint(curvedPath, NULL, x21, y21, point2.x, point2.y);
  604. animation.path = curvedPath;
  605. CGPathRelease(curvedPath);
  606. //透明度变化
  607. CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];
  608. opacityAnim.fromValue = [NSNumber numberWithFloat:1.0];
  609. opacityAnim.toValue = [NSNumber numberWithFloat:0];
  610. opacityAnim.removedOnCompletion = NO;
  611. opacityAnim.beginTime = 0;
  612. opacityAnim.duration = 3;
  613. //比例
  614. CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
  615. // int scale = arc4random() % 5 + 5;
  616. scaleAnim.fromValue = [NSNumber numberWithFloat:.0];//[NSNumber numberWithFloat:((float)scale / 10)];
  617. scaleAnim.toValue = [NSNumber numberWithFloat:1];
  618. scaleAnim.removedOnCompletion = NO;
  619. scaleAnim.fillMode = kCAFillModeForwards;
  620. scaleAnim.duration = .5;
  621. CAAnimationGroup *animGroup = [CAAnimationGroup animation];
  622. animGroup.animations = [NSArray arrayWithObjects: scaleAnim,opacityAnim,animation, nil];
  623. animGroup.duration = 3;
  624. return animGroup;
  625. }
  626. - (void)showLikeHeartStartRect:(CGRect)frame
  627. {
  628. _lightCount ++;
  629. UIImageView *imageView = [[UIImageView alloc ] initWithFrame:frame];
  630. // imageView.image = [[UIImage imageNamed:@"img_like"] imageWithTintColor:[UIColor randomFlatDarkColor]];
  631. if (_heartImgViewName)
  632. {
  633. imageView.image = [UIImage imageNamed:_heartImgViewName];
  634. }
  635. else
  636. {
  637. int index = arc4random() % 6;
  638. imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"heart%d",index]];
  639. }
  640. [self.superview addSubview:imageView];
  641. imageView.alpha = 0;
  642. [imageView.layer addAnimation:[self hearAnimationFrom:frame] forKey:nil];
  643. FWWeakify(self)
  644. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  645. FWStrongify(self)
  646. [imageView removeFromSuperview];
  647. self.lightCount --;
  648. });
  649. }
  650. #if kSupportIMMsgCache
  651. - (void)showLikeHeartStartRect:(CGRect)frame count:(NSInteger)count
  652. {
  653. for (int i = 0; i < count; i++)
  654. {
  655. [self showLikeHeartStartRectFrameCache:frame];
  656. }
  657. }
  658. - (void)showLikeHeartStartRectFrameCache:(CGRect)frame
  659. {
  660. UIImageView *imageView = nil;
  661. if (self.praiseAnimationCache.count)
  662. {
  663. imageView = [self.praiseAnimationCache objectAtIndex:0];
  664. [self.praiseAnimationCache removeObject:imageView];
  665. imageView.frame = frame;
  666. imageView.hidden = NO;
  667. }
  668. else
  669. {
  670. imageView = [[UIImageView alloc ] initWithFrame:frame];
  671. imageView.image = self.praiseImageCache[arc4random()%self.praiseImageCache.count];
  672. [self.superview addSubview:imageView];
  673. }
  674. imageView.alpha = 0;
  675. [imageView.layer addAnimation:[self hearAnimationFrom:frame] forKey:nil];
  676. FWWeakify(self)
  677. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  678. FWStrongify(self)
  679. [self.praiseAnimationCache addObject:imageView];
  680. });
  681. }
  682. #endif
  683. - (void)updateShowFunc
  684. {
  685. }
  686. @end