BGLiveUIViewController.m 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206
  1. //
  2. // BGLiveUIViewController.m
  3. // FanweLive
  4. //
  5. // Created by xfg on 16/11/23.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "BGLiveUIViewController.h"
  9. #import "BGConversationListController.h"
  10. #import "BGTPlayControllerForPK.h"
  11. #import "BGKSYPlayerControllerForPk.h"
  12. #import "FPKProgress.h"
  13. #import "PKPopView.h"
  14. #import "WMDragView.h"
  15. #import "MGAddWishViewController.h"
  16. #import "BogoPkProgressModel.h"
  17. #import "BogoShopKit.h"
  18. #import "WMDragView.h"
  19. #import "WMDragView.h"
  20. #import "RoomFaceView.h"
  21. #import "RoomFaceModel.h"
  22. #import "choseMuiscVC.h"
  23. #define BEGIN_SLIDE_RATE 0.15 // 当从左往右滑动时,滑动超过了屏幕宽度的BEGIN_SLIDE_RATE时候就向左滑动
  24. #define BEGIN_SLIDE_RATE2 0.3 // 当从上往下滑动时,滑动超过了屏幕高度的BEGIN_SLIDE_RATE时候就切换直播频道
  25. #define DURING_TIME 10
  26. @interface BGLiveUIViewController ()<PKUserListViewDelegate,RoomFaceViewDelegate>
  27. {
  28. PKUserListViewController *pkList;
  29. // BGTPlayControllerForPK *pkView;
  30. // BGTPlayControllerForPK *pkView;
  31. MMAlertView *alert1;
  32. MMAlertView *alert2;
  33. MMAlertView *alert3;
  34. NSString *otherId;
  35. CurrentLiveInfo *_liveInfo;
  36. }
  37. @property(nonatomic, strong) NSString *pkID;
  38. @property(nonatomic, strong) BogoPkProgressModel *model;
  39. @property(nonatomic, strong) RoomFaceView *faceView;
  40. @end
  41. @implementation BGLiveUIViewController
  42. #pragma mark - ----------------------- 直播生命周期 -----------------------
  43. - (void)releaseAll
  44. {
  45. [self removePanGestureRec];
  46. [[NSNotificationCenter defaultCenter] removeObserver:self];
  47. [_imChatVCBgView removeFromSuperview];
  48. _liveController = nil;
  49. _liveItem = nil;
  50. if (self.livePayTimer)
  51. {
  52. [self.livePayTimer invalidate];
  53. self.livePayTimer = nil;
  54. }
  55. if (self.livePayLeftTimer)
  56. {
  57. [self.livePayLeftTimer invalidate];
  58. self.livePayLeftTimer = nil;
  59. }
  60. // 关闭付费的定时器
  61. if (self.livePay.payLiveTime)
  62. {
  63. [self.livePay.payLiveTime invalidate];
  64. self.livePay.payLiveTime = nil;
  65. }
  66. if (self.livePay.payLiveTime)
  67. {
  68. [self.livePay.hostPayLiveTime invalidate];
  69. self.livePay.hostPayLiveTime = nil;
  70. }
  71. if (self.livePay.countDownTime)
  72. {
  73. [self.livePay.countDownTime invalidate];
  74. self.livePay.countDownTime = nil;
  75. }
  76. self.livePay.livController = nil;
  77. }
  78. - (void)dealloc
  79. {
  80. [self releaseAll];
  81. NSLog(ASLocalizedString(@"%s释放"),__func__);
  82. if (_fpkProgress) {
  83. [_pkCountDownView stopTimer];
  84. }
  85. }
  86. #pragma mark 开始直播
  87. - (void)startLive
  88. {
  89. [self.liveView startLive];
  90. }
  91. #pragma mark 暂停直播
  92. - (void)pauseLive
  93. {
  94. [self.liveView pauseLive];
  95. }
  96. #pragma mark 重新开始直播
  97. - (void)resumeLive
  98. {
  99. [self.liveView resumeLive];
  100. }
  101. #pragma mark 结束直播
  102. - (void)endLive
  103. {
  104. [self releaseAll];
  105. [self.liveView endLive];
  106. for (UIView *tmpView in self.liveView.subviews)
  107. {
  108. [tmpView removeFromSuperview];
  109. }
  110. [self.liveView removeFromSuperview];
  111. //2020-1-2 结束-关闭音乐
  112. if (_soundSetView) {
  113. [_soundSetView.player pause];
  114. _soundSetView.player=nil;
  115. }
  116. }
  117. #pragma mark 初始化房间信息等
  118. - (instancetype)initWith:(id<FWShowLiveRoomAble>)liveItem liveController:(id<FWLiveControllerAble>)liveController
  119. {
  120. if (self = [super init])
  121. {
  122. _liveItem = liveItem;
  123. _isHost = [liveItem isHost];
  124. _liveController = liveController;
  125. self.liveView = [[TCShowLiveView alloc] initWith:liveItem liveController:liveController];
  126. self.liveView.uiDelegate = self;
  127. [self.liveView setFrameAndLayout:self.view.bounds];
  128. [self.view addSubview:self.liveView];
  129. self.liveScrollView = [BGTLiveScrollView new];
  130. self.liveScrollView.roomID = [NSString stringWithFormat:@"%d",_liveItem.liveAVRoomId];
  131. self.liveScrollView.contentSize = CGSizeMake(0, kScreenH * 3);
  132. self.liveScrollView.frame = CGRectMake(0, 0, kScreenW, kScreenH);
  133. // self.liveScrollView.frame = CGRectMake(0, self.liveView.topView.height, kScreenW, kScreenH - self.liveView.topView.height - self.liveView.bottomView.height);
  134. self.liveScrollView.pagingEnabled = YES;
  135. self.liveScrollView.delegate = self;
  136. self.liveScrollView.userInteractionEnabled = NO;
  137. [self.liveView addSubview:self.liveScrollView];
  138. // [self.liveScrollView addSubview:self.shopExplainView];
  139. self.pkID = @"";
  140. }
  141. return self;
  142. }
  143. #pragma mark 请求完接口后,刷新直播间相关信息
  144. - (void)refreshLiveItem:(id<FWShowLiveRoomAble>)liveItem liveInfo:(CurrentLiveInfo *)liveInfo
  145. {
  146. _liveItem = liveItem;
  147. _liveInfo = liveInfo;
  148. [self.liveView refreshLiveItem:liveItem liveInfo:liveInfo];
  149. [self setUpLocalizationStringForView:self.liveView.topView];
  150. }
  151. //6-19 修改-endpkview
  152. -(void)viewWillAppear:(BOOL)animated{
  153. [super viewWillAppear:animated];
  154. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endpkview:) name:@"endpkview" object:nil];
  155. }
  156. - (void)viewDidLoad
  157. {
  158. [super viewDidLoad];
  159. [self registerKeyBoardNotification];
  160. _panGestureRec = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveViewWithGesture:)];
  161. _panGestureRec.delegate = self;
  162. [self.view addGestureRecognizer:_panGestureRec];
  163. [GlobalVariables sharedInstance].tliveView = self.view;
  164. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showGiftView:) name:@"showGiftView" object:nil];
  165. //2020-1-4 pk结束
  166. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endpkview:) name:@"endpkview" object:nil];
  167. //5-7 滑动问题
  168. // _panGestureRec.enabled=NO;
  169. // //延迟两秒模拟pk
  170. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  171. // //[self addPKView];
  172. // _panGestureRec.enabled=YES;
  173. // });
  174. // //禁止侧滑
  175. // id traget = self.navigationController.interactivePopGestureRecognizer.delegate;
  176. // UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:traget action:nil];
  177. // [self.view addGestureRecognizer:pan];
  178. }
  179. -(void)PKUserClickItem:(UserModel *)user pk_id:(NSString *)pk_id
  180. {
  181. alert3 = [FanweMessage alert:ASLocalizedString(@"提示")message:ASLocalizedString(@"是否发起pk请求?")destructiveAction:^{
  182. self.pkID = pk_id;
  183. [self requetPkWithUser:user pk_id:pk_id];
  184. // [FanweMessage alert:ASLocalizedString(@"申请pk中,等待对方应答..")];
  185. } cancelAction:^{
  186. }];
  187. [self hiddenPKlist];
  188. }
  189. -(void)requetPkWithUser:(UserModel *)user pk_id:(NSString *)pk_id{
  190. // UserModel *user = self.userlist[index];
  191. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  192. if(![GlobalVariables sharedInstance].openAgora)
  193. {
  194. [mDict setObject:@"pk_tencent" forKey:@"ctl"];
  195. }
  196. else
  197. {
  198. [mDict setObject:@"pk_agora" forKey:@"ctl"];
  199. }
  200. [mDict setObject:@"request_pk" forKey:@"act"];
  201. [mDict setObject:user.user_id forKey:@"pk_emcee_id"];
  202. [mDict setObject:pk_id forKey:@"pk_list_id"];
  203. __weak __typeof(self)weakSelf = self;
  204. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  205. if ([responseJson toInt:@"status"] == 1)
  206. {
  207. NSNumber *pk_id = [responseJson objectForKey:@"pk_id"];
  208. user.pk_id = pk_id.stringValue;
  209. if([self.serviceDelegate respondsToSelector:@selector(pkController:WidthData:)])
  210. {
  211. [self.serviceDelegate pkController:0 WidthData:user];
  212. }
  213. alert1 = [FanweMessage alert:ASLocalizedString(@"提示")message:ASLocalizedString(@"申请pk中,等待对方应答..")isHideTitle:NO destructiveTitle:ASLocalizedString(@"取消pk")destructiveAction:^{
  214. if([self.serviceDelegate respondsToSelector:@selector(pkController:WidthData:)])
  215. {
  216. [self.serviceDelegate pkController:3 WidthData:user];
  217. }
  218. }];
  219. // [self PKUserClickItem:user];
  220. // if([self.pDelegate respondsToSelector:@selector(PKUserClickItem:)])
  221. // {
  222. // [weakSelf.pDelegate PKUserClickItem:user];
  223. // }
  224. }
  225. else
  226. {
  227. [FanweMessage alert:responseJson[@"msg"]];
  228. // [[BGHUDHelper sharedInstance] tipMessage:responseJson[@"msg"]];
  229. }
  230. } FailureBlock:^(NSError *error) {
  231. }];
  232. }
  233. -(void)receiveRejectPkWithMsg:(NSString *)msg{
  234. [FanweMessage alertController:msg viewController:self destructiveAction:^{
  235. } cancelAction:nil];
  236. [alert1 hide];
  237. alert1 = nil;
  238. }
  239. -(void)receiveCanclePk{
  240. [FanweMessage alert:ASLocalizedString(@"提示")message:ASLocalizedString(@"对方取消PK")isHideTitle:NO destructiveTitle:ASLocalizedString(@"确定")destructiveAction:nil];
  241. [alert1 hide];
  242. alert1 = nil;
  243. [self hiddenPKlist];
  244. }
  245. -(void)pkViewWith:(NSString *)uid
  246. {
  247. [self hiddenPKlist];
  248. [alert1 hide];
  249. alert1 = nil;
  250. self.pkID = uid;
  251. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  252. if(![GlobalVariables sharedInstance].openAgora)
  253. {
  254. [mDict setObject:@"pk_tencent" forKey:@"ctl"];
  255. }
  256. else
  257. {
  258. [mDict setObject:@"pk_agora" forKey:@"ctl"];
  259. }
  260. [mDict setObject:@"request_get_pk_info2" forKey:@"act"];
  261. [mDict setObject:uid.length ? uid : @"" forKey:@"pk_id"];
  262. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson){
  263. if ([responseJson toInt:@"status"] == 1 || [responseJson toInt:@"status"] == 2)
  264. {
  265. //NSString *play_url2 = [responseJson valueForKey:@"play_url2"];
  266. self.model = [BogoPkProgressModel mj_objectWithKeyValues:responseJson];
  267. if ([self.model.group_id2 isEqualToString:[NSString stringWithFormat:@"%d",[_liveItem liveAVRoomId]]]) {
  268. NSArray<BogoPkProgressGiftModel *> *gift_list2 = self.model.gift_list2;
  269. self.model.gift_list2 = self.model.gift_list1;
  270. self.model.gift_list1 = gift_list2;
  271. }
  272. _fpkProgress.model = self.model;
  273. int timer = [responseJson toInt:@"pk_time"];
  274. NSLog(@"189responseJson:%@",responseJson);
  275. [_fpkProgress setLeftIsMe:YES];
  276. BOOL leftIsMe = NO;
  277. BOOL wodezhubois1;
  278. timer = [responseJson toInt:@"pk_time"];
  279. //这里要判断几种情况 先判断 第一 进入是观众的话
  280. NSString *pk_status = [responseJson valueForKey:@"pk_status"];
  281. // 1PK中,2是惩罚
  282. if (pk_status.integerValue == 0){
  283. //非PK状态,不显示PK相关View
  284. return;
  285. }
  286. if(!_isHost)
  287. {
  288. //去除当前主播id
  289. NSString *live1id = [NSString stringWithFormat:@"%@",[responseJson valueForKey:@"emcee_user_id1"]];
  290. if([[_liveItem liveHost].imUserId isEqualToString:live1id])
  291. {
  292. //如果当前等于主播1的话就去主播2
  293. NSString *play_url2 = [responseJson valueForKey:@"play_url2"];
  294. [self addPKViewWithURL:play_url2 WithViewType:1 widthTime:timer WithDic:responseJson AndIsNO1:NO status:[responseJson toInt:@"status"] pkStatus:pk_status.intValue];
  295. //此时 uid2 在左面
  296. [self swapPlayer];
  297. leftIsMe = YES;
  298. wodezhubois1 = YES;
  299. }
  300. else
  301. {
  302. //同上
  303. NSString *play_url2 = [responseJson valueForKey:@"play_url1"];
  304. [self addPKViewWithURL:play_url2 WithViewType:1 widthTime:timer WithDic:responseJson AndIsNO1:YES status:[responseJson toInt:@"status"] pkStatus:pk_status.intValue];
  305. wodezhubois1 = NO;
  306. //此时 uid2 在右面
  307. }
  308. }
  309. else
  310. {
  311. //始终去主播1的
  312. NSDictionary * userInfo = @{@"roomid":[NSString stringWithFormat:@"PK%@",[responseJson valueForKey:@"emcee_user_id1"]]};
  313. [[NSNotificationCenter defaultCenter] postNotificationName:@"KPKWithRoomID" object:self userInfo:userInfo];
  314. //如果我是主播的话,判断下我是属于2还是1
  315. //去除当前主播id
  316. NSString *live1id = [NSString stringWithFormat:@"%@",[responseJson valueForKey:@"emcee_user_id1"]];
  317. if([[IMAPlatform sharedInstance].host.userId isEqualToString:live1id])
  318. {
  319. //如果当前等于主播1的话就去主播2
  320. NSString *play_url2 = [responseJson valueForKey:@"play_url2"];
  321. [self addPKViewWithURL:play_url2 WithViewType:1 widthTime:timer WithDic:responseJson AndIsNO1:NO status:[responseJson toInt:@"status"] pkStatus:pk_status.intValue];
  322. //此时 uid2 在左面,也是是我在右面
  323. leftIsMe = YES;
  324. wodezhubois1 = YES;
  325. }
  326. else
  327. {
  328. //同上
  329. NSString *play_url2 = [responseJson valueForKey:@"play_url1"];
  330. [self addPKViewWithURL:play_url2 WithViewType:1 widthTime:timer WithDic:responseJson AndIsNO1:YES status:[responseJson toInt:@"status"] pkStatus:pk_status.intValue];
  331. //此时 uid2 在右面,也就是我在右面
  332. [self swapPlayer];
  333. wodezhubois1 = NO;
  334. }
  335. }
  336. _fpkProgress.leftIsMe = leftIsMe;
  337. }
  338. else
  339. {
  340. [[BGHUDHelper sharedInstance] tipMessage:[responseJson valueForKey:@"error"]];
  341. }
  342. } FailureBlock:^(NSError *error) {
  343. }];
  344. }
  345. //把uid2 在左面的搞的右面去
  346. - (void)swapPlayer {
  347. }
  348. -(void)clickChangeRoom:(UIButton *)sender{
  349. // if (_serviceDelegate && [_serviceDelegate respondsToSelector:@selector(protocolGetVideoWithRoomID:)])
  350. // {
  351. // [_serviceDelegate protocolGetVideoWithRoomID:group_id];
  352. // }
  353. }
  354. #pragma mark - 设置pk页面播放
  355. -(void)addPKViewWithURL:(NSString *)url WithViewType:(int )type widthTime:(int )time WithDic:(NSDictionary *)dic AndIsNO1:(BOOL)isOne status:(int)status pkStatus:(int)pkStatus
  356. {
  357. //2020-1-3 修改pk开始样式
  358. UIImageView *pkcenterImgv=[[UIImageView alloc]initWithFrame:CGRectMake(kScreenW/2-50, 67 + kStatusBarHeight + kScreenW * 2 / 3/2 +20-50, 100, 100)];
  359. pkcenterImgv.image=[UIImage imageNamed:@"pkcenter"];
  360. [self.view addSubview:pkcenterImgv];
  361. UIImageView *pkleftImgv, *pkrightImgv;
  362. for (int i=0; i<2; i++) {
  363. UIImageView *pkbackImgv=[[UIImageView alloc]init];
  364. [self.view addSubview:pkbackImgv];
  365. UIImageView *pkavatarImgv=[[UIImageView alloc]init];
  366. [pkbackImgv addSubview:pkavatarImgv];
  367. pkavatarImgv.layer.cornerRadius=42/2;
  368. pkavatarImgv.layer.masksToBounds=YES;
  369. UILabel *namelab=[[UILabel alloc]init];
  370. namelab.textColor=kWhiteColor;
  371. namelab.font=[UIFont systemFontOfSize:12];
  372. [pkbackImgv addSubview:namelab];
  373. UILabel *namedelab=[[UILabel alloc]init];
  374. namedelab.textColor=kWhiteColor;
  375. namedelab.font=[UIFont systemFontOfSize:12];
  376. [pkbackImgv addSubview:namedelab];
  377. if (i==0) {
  378. pkbackImgv.frame=CGRectMake(0, 67 + kStatusBarHeight + kScreenW * 2 / 3 +20+20, 145, 58);
  379. pkbackImgv.image=[UIImage imageNamed:@"我方"];
  380. pkleftImgv=pkbackImgv;
  381. pkavatarImgv.frame=CGRectMake(15, (58-42)/2, 42, 42);
  382. [pkavatarImgv sd_setImageWithURL:[NSURL URLWithString:isOne?[dic valueForKey:@"head_image2"]:[dic valueForKey:@"head_image1"]] placeholderImage:[UIImage imageNamed:@"DefaultImg"]];
  383. namelab.frame=CGRectMake(15+42+5, 58/2-20, 65, 25);
  384. // namelab.numberOfLines = 2;
  385. // namelab.lineBreakMode = NSLineBreakByCharWrapping;
  386. namelab.text=isOne?[dic valueForKey:@"name2"]:[dic valueForKey:@"name1"];
  387. namelab.left = pkavatarImgv.right + 5;
  388. namedelab.frame=CGRectMake(15+42+5, 58/2 + 5, 145-15-42-5, 20);
  389. namedelab.text= ASLocalizedString(@"我方");
  390. // isOne?ASLocalizedString(@"对方"):ASLocalizedString(@"我方");
  391. }else{
  392. pkbackImgv.frame=CGRectMake(kScreenW-145, 67 + kStatusBarHeight + kScreenW * 2 / 3 +20+20, 145, 58);
  393. pkbackImgv.image=[UIImage imageNamed:@"对方"];
  394. pkrightImgv=pkbackImgv;
  395. pkavatarImgv.frame=CGRectMake(145-15-42, (58-42)/2, 42, 42);
  396. [pkavatarImgv sd_setImageWithURL:[NSURL URLWithString:isOne?[dic valueForKey:@"head_image1"]:[dic valueForKey:@"head_image2"]] placeholderImage:[UIImage imageNamed:@"DefaultImg"]];
  397. namelab.frame=CGRectMake(0, 58/2-20, 65, 25);
  398. namelab.text=isOne?[dic valueForKey:@"name1"]:[dic valueForKey:@"name2"];
  399. // namelab.numberOfLines = 2;
  400. // namelab.lineBreakMode = NSLineBreakByCharWrapping;
  401. namelab.textAlignment=NSTextAlignmentRight;
  402. namelab.right = pkbackImgv.width - pkavatarImgv.left - 5;
  403. namelab.left = 10;
  404. namedelab.frame=CGRectMake(0, 58/2 + 5, 145-15-42-5, 20);
  405. namedelab.text = ASLocalizedString(@"对方");
  406. // isOne?ASLocalizedString(@"我方"):ASLocalizedString(@"对方");
  407. namedelab.textAlignment=NSTextAlignmentRight;
  408. }
  409. }
  410. otherId = dic[@"emcee_user_id1"];
  411. if ([otherId isEqualToString:[IMAPlatform sharedInstance].host.imUserId]) {
  412. otherId = dic[@"emcee_user_id2"];
  413. }
  414. NSMutableDictionary *postObj = [NSMutableDictionary dictionaryWithDictionary:@{@"isFull":@0,@"playUrl":url.length ? url : @""}];
  415. if(type == 1)
  416. {
  417. //type == 3代表要置换页面
  418. postObj = [NSMutableDictionary dictionaryWithDictionary:@{@"isFull":@3,@"playUrl":url.length ? url : @"",@"touid":otherId}];
  419. }
  420. if(self.model)
  421. {
  422. [postObj setObject:self.model forKey:@"model"];
  423. }
  424. [[NSNotificationCenter defaultCenter]postNotificationName:@"onPKViewChange" object:nil userInfo:postObj];
  425. //2020-1-3 修改pk倒计时
  426. if (!_pkCountDownView) {
  427. _pkCountDownView = [[FPKCountDownView alloc]initWithFrame:CGRectMake(0, 67 + kStatusBarHeight +10+20, kScreenW, 20) liveItem:_liveItem];
  428. _pkCountDownView.pkid = [NSString stringWithFormat:@"%@",dic[@"id"]];
  429. _pkCountDownView.pktype=@"pk";
  430. [self.view addSubview:_pkCountDownView];
  431. // [self.view bringSubviewToFront:_pkCountDownView];
  432. }
  433. if (pkStatus == 2) {
  434. [_fpkProgress switchToPunish:(120+time)];
  435. //2020-1-3 修改惩罚倒计时
  436. _pkCountDownView.frame=CGRectMake(0, 67 + kStatusBarHeight + kScreenW * 2 / 3 +20-38, kScreenW, 38);
  437. _pkCountDownView.pktype=@"cf";
  438. [_pkCountDownView switchToPunish:(120+time)];
  439. }else{
  440. _pkCountDownView.countDown = time;
  441. }
  442. //2020-1-4 修改pk
  443. int64_t delayInSeconds = 3.0; // 延迟的时间
  444. __weak typeof(self)weakSelf = self;
  445. if (_fpkProgress) {
  446. _fpkProgress.room_id = _liveInfo.room_id;
  447. }
  448. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  449. pkcenterImgv.hidden=YES;
  450. pkleftImgv.hidden=YES;
  451. pkrightImgv.hidden=YES;
  452. if(!_fpkProgress)
  453. {
  454. //2020-1-3 修改pk进度
  455. // BGKSYLiveController *liveVC = (BGKSYLiveController *)_liveController;
  456. _fpkProgress = [[FPKProgress alloc] initWithFrame:CGRectMake(0, kStatusBarHeight + 53 + kScreenW * 2.4 / 3, kScreenW, kRealValue(20 + 36))];
  457. [weakSelf.view addSubview:_fpkProgress];
  458. [weakSelf.view insertSubview:_fpkProgress belowSubview:_liveView];
  459. }
  460. //进度条
  461. _fpkProgress.leftValue = 0;
  462. _fpkProgress.rightValue = 0;
  463. _fpkProgress.avatar = isOne?[dic valueForKey:@"head_image1"]:[dic valueForKey:@"head_image2"];
  464. _fpkProgress.otherId = isOne?[dic valueForKey:@"group_id1"]:[dic valueForKey:@"group_id2"];
  465. //2020-1-4 修改pk结束后
  466. _myavatar = isOne?[dic valueForKey:@"head_image2"]:[dic valueForKey:@"head_image1"];
  467. _myId = isOne?[dic valueForKey:@"name2"]:[dic valueForKey:@"name1"];
  468. _avatar=isOne?[dic valueForKey:@"head_image1"]:[dic valueForKey:@"head_image2"];
  469. _otherId = isOne?[dic valueForKey:@"name1"]:[dic valueForKey:@"name2"];
  470. if([[dic allKeys] containsObject:@"pk_ticket1"])
  471. {
  472. if ([dic[@"emcee_user_id1"] isEqualToString:[IMAPlatform sharedInstance].host.imUserId] || [_liveInfo.user_id isEqualToString:dic[@"emcee_user_id1"]]) {
  473. _fpkProgress.leftValue = [[dic valueForKey:@"pk_ticket1"] intValue];
  474. _fpkProgress.rightValue = [[dic valueForKey:@"pk_ticket2"] intValue];
  475. }else{
  476. _fpkProgress.leftValue = [[dic valueForKey:@"pk_ticket2"] intValue];
  477. _fpkProgress.rightValue = [[dic valueForKey:@"pk_ticket1"] intValue];
  478. }
  479. if ([dic[@"pk_status"] integerValue] == 2) {
  480. [_fpkProgress showPublishView];
  481. }
  482. }
  483. if ([self.model.group_id2 isEqualToString:[NSString stringWithFormat:@"%d",[_liveItem liveAVRoomId]]]) {
  484. NSArray<BogoPkProgressGiftModel *> *gift_list2 = self.model.gift_list2;
  485. self.model.gift_list2 = self.model.gift_list1;
  486. self.model.gift_list1 = gift_list2;
  487. }
  488. _fpkProgress.room_id = _liveInfo.room_id;
  489. _fpkProgress.model = self.model;
  490. });
  491. }
  492. -(void)pkViewUpdateData:(NSDictionary *)dic
  493. {
  494. if ([dic[@"emcee_user_id1"] isEqualToString:[IMAPlatform sharedInstance].host.imUserId] || [_liveInfo.user_id isEqualToString:dic[@"emcee_user_id1"]]) {
  495. _fpkProgress.leftValue = [[dic valueForKey:@"pk_ticket1"] intValue];
  496. _fpkProgress.rightValue = [[dic valueForKey:@"pk_ticket2"] intValue];
  497. }else{
  498. _fpkProgress.leftValue = [[dic valueForKey:@"pk_ticket2"] intValue];
  499. _fpkProgress.rightValue = [[dic valueForKey:@"pk_ticket1"] intValue];
  500. }
  501. [self getPKInfoWithPKID:self.pkID];
  502. }
  503. -(void)getPKInfoWithPKID:(NSString *)pk_ID{
  504. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  505. if(![GlobalVariables sharedInstance].openAgora)
  506. {
  507. [mDict setObject:@"pk_tencent" forKey:@"ctl"];
  508. }
  509. else
  510. {
  511. [mDict setObject:@"pk_agora" forKey:@"ctl"];
  512. }
  513. [mDict setObject:@"request_get_pk_info2" forKey:@"act"];
  514. [mDict setObject:pk_ID.length ? pk_ID : @"" forKey:@"pk_id"];
  515. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  516. if ([responseJson toInt:@"status"] == 1 || [responseJson toInt:@"status"] == 2)
  517. {
  518. //NSString *play_url2 = [responseJson valueForKey:@"play_url2"];
  519. self.model = [BogoPkProgressModel mj_objectWithKeyValues:responseJson];
  520. // if ([self.model.group_id2 isEqualToString:[NSString stringWithFormat:@"%d",[_liveItem liveAVRoomId]]]) {
  521. // NSArray<BogoPkProgressGiftModel *> *gift_list2 = self.model.gift_list2;
  522. //
  523. // self.model.gift_list2 = self.model.gift_list1;
  524. // self.model.gift_list1 = gift_list2;
  525. // }
  526. _fpkProgress.room_id = _liveInfo.room_id;
  527. _fpkProgress.model = self.model;
  528. }
  529. } FailureBlock:^(NSError *error) {
  530. }];
  531. }
  532. //2020-1-4 pk结束
  533. -(void)endpkview:(NSNotification *)noti{
  534. }
  535. //2020-1-4 pk结束
  536. -(void)showGiftView:(NSNotification *)noti{
  537. NSLog(@"点击的用户ID %@",noti.userInfo[@"uid"])
  538. [_liveView showGiftView:noti.userInfo[@"uid"]];
  539. }
  540. -(void)pkVivewEnd:(NSString *)win_user_id anddic:(NSDictionary *)dic{
  541. // [_showView removeFromSuperview];
  542. // [_showView removeAllSubViews];
  543. // _showView=nil;
  544. NSString * _leftValue=@"0";
  545. NSString * _rightValue=@"0";
  546. if (dic.count!=0) {
  547. NSLog(@"%@",win_user_id);
  548. NSLog(@"%@",[IMAPlatform sharedInstance].host.imUserId);
  549. if ([dic[@"emcee_user_id1"] isEqualToString:[IMAPlatform sharedInstance].host.imUserId] || [_liveInfo.user_id isEqualToString:dic[@"emcee_user_id1"]]) {
  550. // == [dic[@"emcee_user_id1"] intValue] && win_user_id.intValue == [[IMAPlatform sharedInstance].host.imUserId intValue]) {
  551. _leftValue = [dic valueForKey:@"pk_ticket1"];
  552. _rightValue = [dic valueForKey:@"pk_ticket2"];
  553. }else{
  554. _leftValue = [dic valueForKey:@"pk_ticket2"];
  555. _rightValue = [dic valueForKey:@"pk_ticket1"];
  556. }
  557. // if (win_user_id.intValue
  558. // == [dic[@"emcee_user_id1"] intValue] && win_user_id.intValue == [[IMAPlatform sharedInstance].host.imUserId intValue]) {
  559. // _leftValue = [dic valueForKey:@"pk_ticket1"];
  560. // _rightValue = [dic valueForKey:@"pk_ticket2"];
  561. // }else{
  562. // _leftValue = [dic valueForKey:@"pk_ticket2"];
  563. // _rightValue = [dic valueForKey:@"pk_ticket1"];
  564. // }
  565. }
  566. UIView *showView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenHeight)];
  567. showView.backgroundColor=[kBlackColor colorWithAlphaComponent:0.6];
  568. [self.view addSubview:showView];
  569. self.showView=showView;
  570. [self.view bringSubviewToFront:showView];
  571. UIImageView *backImgv=[[UIImageView alloc]initWithFrame:CGRectMake(kScreenW/2-276/2, kScreenHeight/2-122, 276, 244)];
  572. backImgv.image=[UIImage imageNamed:@"弹窗背景"];
  573. [showView addSubview:backImgv];
  574. UIImageView *topImgv=[[UIImageView alloc]initWithFrame:CGRectMake(kScreenW/2-179/2, kScreenHeight/2-244/2-52/2, 179, 52)];
  575. topImgv.image=[UIImage imageNamed:@"PK结束"];
  576. [showView addSubview:topImgv];
  577. showView.userInteractionEnabled=YES;
  578. backImgv.userInteractionEnabled=YES;
  579. UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(backImgv.width-30, 10, 20, 20)];
  580. [btn setImage:[UIImage imageNamed:@"pk关闭"] forState:UIControlStateNormal];
  581. [btn addTarget:self action:@selector(pushToCancleClick) forControlEvents:UIControlEventTouchUpInside];
  582. [backImgv addSubview:btn];
  583. UIImageView *centerImgv=[[UIImageView alloc]initWithFrame:CGRectMake(backImgv.width/2-30/2, 52/2+15+30-17/2, 30, 17)];
  584. centerImgv.image=[UIImage imageNamed:@"PK后"];
  585. [backImgv addSubview:centerImgv];
  586. for (int i=0; i<2; i++) {
  587. UIImageView *pkavatarImgv=[[UIImageView alloc]init];
  588. [backImgv addSubview:pkavatarImgv];
  589. pkavatarImgv.layer.cornerRadius=60/2;
  590. pkavatarImgv.layer.masksToBounds=YES;
  591. UILabel *namelab=[[UILabel alloc]init];
  592. namelab.textColor=RGB(102, 102, 102);
  593. namelab.textAlignment=NSTextAlignmentCenter;
  594. namelab.font=[UIFont systemFontOfSize:13];
  595. [backImgv addSubview:namelab];
  596. UIImageView *footImgv=[[UIImageView alloc]init];
  597. [backImgv addSubview:footImgv];
  598. UILabel *numlab=[[UILabel alloc]init];
  599. numlab.backgroundColor=RGB(245, 245, 245);
  600. numlab.textColor=RGB(148, 143, 255);
  601. numlab.textAlignment=NSTextAlignmentCenter;
  602. numlab.font=[UIFont systemFontOfSize:13];
  603. [backImgv addSubview:numlab];
  604. numlab.layer.cornerRadius=3;
  605. numlab.layer.masksToBounds=YES;
  606. if (i==0) {
  607. pkavatarImgv.frame=CGRectMake(backImgv.width/2/2-30, 52/2+15, 60, 60);
  608. [pkavatarImgv sd_setImageWithURL:[NSURL URLWithString:_myavatar] placeholderImage:[UIImage imageNamed:@"com_preload_head_img"]];
  609. namelab.frame=CGRectMake(0, 52/2+15+65, backImgv.width/2, 15);
  610. namelab.text=_myId;
  611. if (_leftValue.intValue > _rightValue.intValue) {
  612. //左边胜利,右边失败
  613. footImgv.frame=CGRectMake(backImgv.width/2/2-91/2, 52/2+15+65+20, 91, 48);
  614. footImgv.image=[UIImage imageNamed:@"胜利"];
  615. }else if (_leftValue.intValue < _rightValue.intValue){
  616. //左边失败,右边胜利
  617. footImgv.frame=CGRectMake(backImgv.width/2/2-78/2, 52/2+15+65+20+2.5, 78, 43);
  618. footImgv.image=[UIImage imageNamed:@"成功"];
  619. }else{
  620. footImgv.frame=CGRectMake(backImgv.width/2/2-56/2, 52/2+15+65+20-(56-48)/2, 56, 56);
  621. footImgv.image=[UIImage imageNamed:@"平局"];
  622. //2020-1-7 平局
  623. UILabel *lab=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 56, 56)];
  624. lab.font=[UIFont boldSystemFontOfSize:12];
  625. lab.text=ASLocalizedString(@"平局");
  626. lab.textColor=kWhiteColor;
  627. lab.textAlignment=NSTextAlignmentCenter;
  628. [footImgv addSubview:lab];
  629. }
  630. numlab.frame=CGRectMake(backImgv.width/2/2-83/2, 52/2+15+65+20+50, 83, 25);
  631. numlab.text=[NSString stringWithFormat:@"%@",_leftValue];
  632. }else{
  633. pkavatarImgv.frame=CGRectMake(backImgv.width/2+backImgv.width/2/2-30, 52/2+15, 60, 60);
  634. [pkavatarImgv sd_setImageWithURL:[NSURL URLWithString:_avatar] placeholderImage:[UIImage imageNamed:@"com_preload_head_img"]];
  635. namelab.frame=CGRectMake(backImgv.width/2, 52/2+15+65, backImgv.width/2, 15);
  636. namelab.text=_otherId;
  637. if (_leftValue.intValue > _rightValue.intValue) {
  638. //左边胜利,右边失败
  639. footImgv.frame=CGRectMake(backImgv.width/2+backImgv.width/2/2-78/2, 52/2+15+65+20+2.5, 78, 43);
  640. footImgv.image=[UIImage imageNamed:@"成功"];
  641. }else if (_leftValue.intValue < _rightValue.intValue){
  642. //左边失败,右边胜利
  643. footImgv.frame=CGRectMake(backImgv.width/2+backImgv.width/2/2-91/2, 52/2+15+65+20, 91, 48);
  644. footImgv.image=[UIImage imageNamed:@"胜利"];
  645. }else{
  646. footImgv.frame=CGRectMake(backImgv.width/2+backImgv.width/2/2-56/2, 52/2+15+65+20-(56-48)/2, 56, 56);
  647. footImgv.image=[UIImage imageNamed:@"平局"];
  648. //2020-1-7 平局
  649. UILabel *lab=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 56, 56)];
  650. lab.font=[UIFont boldSystemFontOfSize:12];
  651. lab.text=ASLocalizedString(@"平局");
  652. lab.textColor=kWhiteColor;
  653. lab.textAlignment=NSTextAlignmentCenter;
  654. [footImgv addSubview:lab];
  655. }
  656. numlab.frame=CGRectMake(backImgv.width/2+backImgv.width/2/2-83/2, 52/2+15+65+20+50, 83, 25);
  657. numlab.text=[NSString stringWithFormat:@"%@",_rightValue];
  658. }
  659. }
  660. }
  661. -(void)pushToCancleClick{
  662. [_showView removeFromSuperview];
  663. [_showView removeAllSubViews];
  664. _showView=nil;
  665. }
  666. - (void)switchToPunish:(int)time{
  667. //切换pk视图到惩罚视图
  668. [_fpkProgress switchToPunish:time];
  669. //2020-1-3 修改惩罚倒计时
  670. _pkCountDownView.frame=CGRectMake(0, 67 + kStatusBarHeight + kScreenW * 2 / 3 +20-38, kScreenW, 38);
  671. _pkCountDownView.pktype=@"cf";
  672. [_pkCountDownView switchToPunish:time];
  673. }
  674. //self.layer.transform = CATransform3DMakeScale(1.2f, 1.2f, 1.0f);
  675. //self.alpha = 0.0f;
  676. //
  677. //[UIView animateWithDuration:self.animationDuration
  678. // delay:0.0 options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState
  679. // animations:^{
  680. //
  681. // self.layer.transform = CATransform3DIdentity;
  682. // self.alpha = 1.0f;
  683. //
  684. // } completion:^(BOOL finished) {
  685. //
  686. // if ( self.showCompletionBlock )
  687. // {
  688. // self.showCompletionBlock(self, finished);
  689. // }
  690. // }];
  691. -(void)pkVivewHidden
  692. {
  693. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  694. if(![GlobalVariables sharedInstance].openAgora)
  695. {
  696. [dict setObject:@"pk_tencent" forKey:@"ctl"];
  697. }
  698. else
  699. {
  700. [dict setObject:@"pk_agora" forKey:@"ctl"];
  701. }
  702. [dict setValue:@"request_end_pk" forKey:@"act"];
  703. [[NetHttpsManager manager] POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  704. if ([responseJson toInt:@"status"] == 1) {
  705. NSLog(ASLocalizedString(@"结束PK请求成功responseJson:%@"),responseJson);
  706. }else{
  707. NSLog(ASLocalizedString(@"结束PK请求失败responseJson:%@"),responseJson);
  708. }
  709. } FailureBlock:^(NSError *error) {
  710. NSLog(ASLocalizedString(@"结束PK请求失败error:%@"),error);
  711. }];
  712. [_pkView stopPlay];
  713. [_pkView.view removeFromSuperview];
  714. [_pkView removeFromParentViewController];
  715. _pkView = nil;
  716. [_pkCountDownView stopTimer];
  717. [_pkCountDownView removeFromSuperview];
  718. _pkCountDownView = nil;
  719. NSDictionary *postObj = @{@"isFull":@1};
  720. [[NSNotificationCenter defaultCenter]postNotificationName:@"onPKViewChange" object:nil userInfo:postObj];
  721. //通知主线程刷新
  722. // dispatch_async(dispatch_get_main_queue(), ^{
  723. NSArray * views = [_fpkProgress subviews];
  724. for (UIView * v in views){
  725. [v removeFromSuperview];
  726. }
  727. [_fpkProgress setLeftValue:0];
  728. [_fpkProgress setRightValue:0];
  729. [_fpkProgress removeFromSuperview];
  730. _fpkProgress = nil;
  731. // });
  732. }
  733. -(void)hiddenPKlist
  734. {
  735. pkList.view.hidden = YES;
  736. pkList = nil;
  737. }
  738. -(void)showPKlist
  739. {
  740. if (_fpkProgress) {
  741. PKPopView *popView = [[PKPopView alloc]initWithType:PKPopViewTypeDetail];
  742. popView.frame = CGRectMake(0, kScreenH, kScreenW, 250);
  743. [popView setOtherId:otherId];
  744. [popView setClickEndPkBtnBlock:^{
  745. //点击了结束PK按钮
  746. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  747. if(![GlobalVariables sharedInstance].openAgora)
  748. {
  749. [dict setObject:@"pk_tencent" forKey:@"ctl"];
  750. }
  751. else
  752. {
  753. [dict setObject:@"pk_agora" forKey:@"ctl"];
  754. }
  755. [dict setValue:@"request_end_pk" forKey:@"act"];
  756. [self.httpsManager POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  757. if ([responseJson toInt:@"status"] == 1) {
  758. NSLog(ASLocalizedString(@"结束PK请求成功responseJson:%@"),responseJson);
  759. [[NSNotificationCenter defaultCenter] postNotificationName:@"endPunish" object:nil];
  760. }else{
  761. NSLog(ASLocalizedString(@"结束PK请求失败responseJson:%@"),responseJson);
  762. [[NSNotificationCenter defaultCenter] postNotificationName:@"endPunish" object:nil];
  763. }
  764. } FailureBlock:^(NSError *error) {
  765. NSLog(ASLocalizedString(@"结束PK请求失败error:%@"),error);
  766. [[NSNotificationCenter defaultCenter] postNotificationName:@"endPunish" object:nil];
  767. }];
  768. }];
  769. [popView show:self.view];
  770. //[popView show:[UIApplication sharedApplication].keyWindow];
  771. //2020-1-4 最上方
  772. //[[UIApplication sharedApplication].keyWindow.viewController.view bringSubviewToFront:popView];
  773. }else{
  774. // NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  775. // [dict setValue:@"pk_tencent" forKey:@"ctl"];
  776. // [dict setValue:@"request_end_pk" forKey:@"act"];
  777. // [[NetHttpsManager manager] POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  778. // if ([responseJson toInt:@"status"] == 1) {
  779. // NSLog(ASLocalizedString(@"结束PK请求成功responseJson:%@"),responseJson);
  780. // }else{
  781. // NSLog(ASLocalizedString(@"结束PK请求失败responseJson:%@"),responseJson);
  782. // }
  783. // } FailureBlock:^(NSError *error) {
  784. // NSLog(ASLocalizedString(@"结束PK请求失败error:%@"),error);
  785. // }];
  786. if(pkList == nil)
  787. {
  788. pkList = [[PKUserListViewController alloc] init];
  789. pkList.pDelegate = self;
  790. [self addChildViewController:pkList];
  791. pkList.view.frame = CGRectMake(0, kScreenH/2, kScreenW, kScreenH/2);
  792. [self.view addSubview:pkList.view];
  793. }
  794. pkList.view.hidden = NO;
  795. [pkList reloadData];
  796. }
  797. }
  798. -(void)closeUserListView{
  799. [self hiddenPKlist];
  800. }
  801. -(void)showWishView{
  802. if (!_wishView) {
  803. _wishView = [[MGLiveWishView alloc]initWithFrame:CGRectMake(0, kScreenH / 2, kScreenW, kScreenH / 2)];
  804. _wishView.roomId=[NSString stringWithFormat:@"%d",[_liveItem liveAVRoomId]];
  805. __weak __typeof(self)weakSelf = self;
  806. _wishView.clickLiveWishBlock = ^(MGADD_WISH wishType) {
  807. // [weakSelf.wishView hide];
  808. MGAddWishViewController *vc = [[MGAddWishViewController alloc]initWithWishType:wishType];
  809. vc.roomId=[NSString stringWithFormat:@"%d",[_liveItem liveAVRoomId]];
  810. vc.clickGiftCellBlcok = ^(MGLiveWishModel * _Nonnull wishModel) {
  811. wishModel.id = @"";
  812. [weakSelf.wishView.listArr addObject:wishModel];
  813. [weakSelf.wishView.tableView reloadData];
  814. NSLog(@"%@",weakSelf.wishView.listArr);
  815. };
  816. [weakSelf.navigationController pushViewController:vc animated:YES];
  817. };
  818. //触发隐藏心愿的block
  819. _wishView.clickHideLiveWishBlock = ^{
  820. [weakSelf.liveView.livewWishView requestModel:[NSString stringWithFormat:@"%d",[_liveItem liveAVRoomId]]];
  821. //[weakSelf.liveView.livewWishView requestModel];
  822. };
  823. }
  824. [_wishView show:self.view];
  825. }
  826. -(void)showSoundView{
  827. __weak __typeof(self)weakSelf = self;
  828. if (!_soundSetView) {
  829. _soundSetView = [[BGSoundEffectsView alloc]initWithFrame:CGRectMake(0, kScreenH / 2, kScreenW, kScreenH / 2)];
  830. _soundSetView.playUrl = ^(BGSoundEffectModel * model) {
  831. if(weakSelf.playUrlBlock)
  832. {
  833. weakSelf.playUrlBlock(model);
  834. }
  835. };
  836. }
  837. [_soundSetView show:self.view];
  838. }
  839. -(void)showSoundSetView:(TCShowLiveView *)showLiveView{
  840. [self showSoundView];
  841. }
  842. -(void)showVipView:(TCShowLiveView *)showLiveView{
  843. if (!_vipView) {
  844. _vipView = [[MGShowVIPListView alloc]initWithFrame:CGRectMake(0, kScreenH / 2, kScreenW, kScreenH *0.6)];
  845. }
  846. [_vipView show:self.view withRoomID:[NSString stringWithFormat:@"%d",[_liveItem liveAVRoomId]]];
  847. }
  848. -(void)addValue
  849. {
  850. //模拟增加
  851. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  852. _fpkProgress.leftValue += 5;
  853. [self addValue];
  854. });
  855. }
  856. #pragma mark - ----------------------- 付费相关UI -----------------------
  857. #pragma mark 付费直播
  858. - (void)beginEnterPayLive:(NSDictionary *)responseJson closeBtn:(UIButton *)closeBtn
  859. {
  860. if (!_isHost && ![[[IMAPlatform sharedInstance].host imUserId] isEqualToString:[[_liveItem liveHost] imUserId]])
  861. {
  862. if (!self.livePay)
  863. {
  864. self.livePay = [[BGLivePayManager alloc]initWithController:self andLiveView:self.liveView andRoomId:[_liveItem liveAVRoomId] andAudienceDict:responseJson andButton:closeBtn];
  865. if ([responseJson toInt:@"is_live_pay"] == 1)
  866. {
  867. if ([_liveItem liveType] == FW_LIVE_TYPE_AUDIENCE)//回播或者云直播的观众
  868. {
  869. if ([responseJson toString:@"preview_play_url"] && ![[responseJson toString:@"preview_play_url"] isEqualToString:@""])
  870. {
  871. [_liveController startLiveRtmp:[responseJson toString:@"preview_play_url"]];
  872. self.livePay.shadowView.backgroundColor = kClearColor;
  873. [_liveController setSDKMute:NO];
  874. if ([responseJson toInt:@"is_only_play_voice"] == 1)//只有声音没有视频画面
  875. {
  876. [self.livePayTimer invalidate];
  877. self.livePayTimer = nil;
  878. [self.livePayLabel removeFromSuperview];
  879. self.livePayLabel = nil;
  880. [self.livePay creatShadowView];
  881. self.livePay.shadowView.hidden = NO;
  882. [self.view bringSubviewToFront:self.livePay.shadowView];
  883. }
  884. }
  885. else
  886. {
  887. self.livePay.shadowView.backgroundColor = kLightGrayColor;
  888. self.livePay.shadowView.hidden = NO;
  889. }
  890. self.livePayCount = [responseJson toInt:@"countdown"];
  891. if (self.livePayCount)
  892. {
  893. self.livePayTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(livePayTimeGo) userInfo:nil repeats:YES];
  894. [[NSRunLoop currentRunLoop] addTimer:self.livePayTimer forMode:NSRunLoopCommonModes];
  895. }
  896. if ([responseJson toInt:@"is_pay_over"] == 0)//开启付费且
  897. {
  898. self.livePayLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 80, kScreenW-20, 90)];
  899. self.livePayLabel.textAlignment = NSTextAlignmentCenter;
  900. self.livePayLabel.font = [UIFont systemFontOfSize:16];
  901. self.livePayLabel.textColor = kWhiteColor;
  902. self.livePayLabel.numberOfLines = 0;
  903. self.livePayLabel.backgroundColor = kClearColor;
  904. if ([responseJson toInt:@"live_pay_type"] == 1)//按场收费
  905. {
  906. self.payLiveType = 1;
  907. self.livePayLabel.text =[NSString stringWithFormat:ASLocalizedString(@"该直播按场收费,您还能预览倒计时%d秒"),self.livePayCount];
  908. }
  909. else
  910. {
  911. self.payLiveType = 0;
  912. self.livePayLabel.text =[NSString stringWithFormat:ASLocalizedString(@"1分钟内重复进入,不重复扣费,请能正常预览视频后,点击进入,以免扣费后不能正常进入,您还能预览倒计时%d秒"),self.livePayCount];
  913. }
  914. [self.view addSubview:self.livePayLabel];
  915. }
  916. [self.view bringSubviewToFront:closeBtn];
  917. }
  918. if ([responseJson toInt:@"live_pay_type"] == 1)//按场收费
  919. {
  920. self.livePay.liveType = 40;
  921. }
  922. if ([responseJson toInt:@"is_pay_over"] == 0)//该参数是否付费过 1付费过 0未付费
  923. {
  924. self.livePay.audienceLeftPView.hidden = YES;//为了预览倒计时和观众左边重叠
  925. self.livePay.is_agree = NO;
  926. }
  927. else
  928. {
  929. self.livePay.is_agree = YES;
  930. }
  931. [self.livePay enterMoneyMode];
  932. [self changePayView:self.liveView];
  933. }
  934. FWWeakify(self)
  935. [self.livePay setBlock:^(NSString *string){
  936. FWStrongify(self)
  937. if ([string isEqualToString:@"1"])
  938. {
  939. [self chargerMoney];
  940. }
  941. else if ([string isEqualToString:@"2"])
  942. {
  943. [self closeLiveController];
  944. }
  945. }];
  946. }
  947. [self changePayViewFrame:self.liveView];
  948. }else
  949. {
  950. if ([responseJson toInt:@"is_live_pay"] == 1 && ([_liveItem liveType] == FW_LIVE_TYPE_HOST ||
  951. [_liveItem liveType] == FW_LIVE_TYPE_RECORD ||
  952. [_liveItem liveType] == FW_LIVE_TYPE_AUDIENCE)) {
  953. if (!self.livePay)
  954. {
  955. self.livePay = [[BGLivePayManager alloc]initWithLiveView:self.liveView andRoomId:[_liveItem liveAVRoomId] andhostDict:responseJson andpayType:[_liveItem liveType]];
  956. }
  957. [self.livePay hostEnterLiveAgainWithMDict:responseJson];
  958. }
  959. }
  960. }
  961. #pragma mark 心跳唤起付费界面
  962. - (void)createPayLiveView:(NSDictionary *)responseJson
  963. {
  964. self.currentMonitorDict = responseJson;
  965. [self.livePay creatViewWithDict:responseJson];
  966. }
  967. #pragma mark IM消息的通知
  968. - (void)getVedioViewWithType:(int)type closeBtn:(UIButton *)closeBtn
  969. {
  970. if (!self.livePay)
  971. {
  972. self.livePay = [[BGLivePayManager alloc]initWithController:self andLiveView:self.liveView andRoomId:[_liveItem liveAVRoomId] andAudienceDict:self.currentMonitorDict andButton:closeBtn];
  973. FWWeakify(self)
  974. [self.livePay setBlock:^(NSString *string)
  975. {
  976. FWStrongify(self)
  977. if ([string isEqualToString:@"1"])
  978. {
  979. [self chargerMoney];
  980. }
  981. else if ([string isEqualToString:@"2"])
  982. {
  983. [self closeLiveController];
  984. }
  985. }];
  986. }
  987. [self.livePay AudienceGetVedioViewWithType:type];
  988. [self changePayViewFrame:self.liveView];
  989. }
  990. #pragma mark 插件中心点击付费
  991. - (void)clickPluginPayItem:(GameModel *)model closeBtn:(UIButton *)closeBtn
  992. {
  993. if ([model.class_name isEqualToString:@"live_pay"]) // 按时付费
  994. {
  995. if ([model.is_active isEqualToString:@"0"])
  996. {
  997. SUS_WINDOW.isShowLivePay = YES;
  998. if (!self.livePay)
  999. {
  1000. self.livePay = [[BGLivePayManager alloc]initWithLiveView:self.liveView andRoomId:[_liveItem liveAVRoomId] andhostDict:self.currentMonitorDict andpayType:[_liveItem liveType]];
  1001. if ([[self.currentMonitorDict objectForKey:@"live"] toInt:@"allow_live_pay"] != 1)
  1002. {
  1003. [FanweMessage alert:ASLocalizedString(@"直播间人数未达到收费人数")];
  1004. }
  1005. else
  1006. {
  1007. self.livePay.buttomFunctionType = self.livePay.liveType = [_liveItem liveType];//通过这个判断来显示付费页面左边的提示
  1008. [self.livePay creatPriceViewWithCount:1];
  1009. }
  1010. }
  1011. else
  1012. {
  1013. self.livePay.buttomFunctionType = self.livePay.liveType = [_liveItem liveType];
  1014. [self.livePay creatViewWithDict:self.currentMonitorDict];
  1015. if ([[self.currentMonitorDict objectForKey:@"live"] toInt:@"allow_live_pay"] != 1)
  1016. {
  1017. [FanweMessage alert:ASLocalizedString(@"直播间人数未达到收费人数")];
  1018. }
  1019. else
  1020. {
  1021. [self.livePay creatPriceViewWithCount:1];
  1022. }
  1023. }
  1024. }
  1025. else
  1026. {
  1027. [FanweMessage alert:ASLocalizedString(@"直播间已处于收费模式中")];
  1028. }
  1029. [self changePayView:self.liveView];
  1030. [self changePayViewFrame:self.liveView];
  1031. }
  1032. else if ([model.class_name isEqualToString:@"live_pay_scene"]) // 按场付费
  1033. {
  1034. if ([model.is_active isEqualToString:@"0"])
  1035. {
  1036. if (!self.livePay)
  1037. {
  1038. self.livePay = [[BGLivePayManager alloc]initWithLiveView:self.liveView andRoomId:[_liveItem liveAVRoomId] andhostDict:self.currentMonitorDict andpayType:[_liveItem liveType]];
  1039. self.livePay.liveType = 40;
  1040. [self.livePay creatPriceViewWithCount:3];
  1041. }
  1042. else
  1043. {
  1044. self.livePay.liveType = 40;
  1045. [self.livePay creatPriceViewWithCount:3];
  1046. }
  1047. }
  1048. else
  1049. {
  1050. [FanweMessage alert:ASLocalizedString(@"直播间已处于收费模式中")];
  1051. }
  1052. [self changePayViewFrame:self.liveView];
  1053. }
  1054. }
  1055. #pragma mark 付费列表倒计时
  1056. - (void)livePayTimeGo
  1057. {
  1058. self.livePayCount --;
  1059. if (self.livePayCount == 0)
  1060. {
  1061. [self.livePayLabel removeFromSuperview];
  1062. self.livePayLabel = nil;
  1063. [self.livePayTimer invalidate];
  1064. self.livePayTimer = nil;
  1065. [_liveController stopLiveRtmp];
  1066. [_liveController setSDKMute:YES];
  1067. }
  1068. self.livePayLabel.text =[NSString stringWithFormat:ASLocalizedString(@"1分钟内重复进入,不重复扣费,请能正常预览视频后,点击进入,以免扣费后不能正常进入,您还能预览倒计时%d秒"),self.livePayCount];
  1069. }
  1070. #pragma mark 付费直播充钱的操作
  1071. - (void)chargerMoney
  1072. {
  1073. // if (!self.rechargeView) {
  1074. // [self.rechargeView show:self.view];
  1075. // }
  1076. if (_serviceDelegate && [_serviceDelegate respondsToSelector:@selector(showRechargeView:)])
  1077. {
  1078. [_serviceDelegate showRechargeView:self];
  1079. }
  1080. }
  1081. #pragma mark 付费直播关闭直播间的操作
  1082. - (void)closeLiveController
  1083. {
  1084. BOOL isDirectCloseLive;
  1085. if (_isHost)
  1086. {
  1087. isDirectCloseLive = NO;
  1088. }
  1089. else
  1090. {
  1091. isDirectCloseLive = YES;
  1092. }
  1093. DebugLog(@"=================:付费直播关闭直播间的操作");
  1094. if (_serviceDelegate && [_serviceDelegate respondsToSelector:@selector(closeCurrentLive:isHostShowAlert:)])
  1095. {
  1096. [_serviceDelegate closeCurrentLive:isDirectCloseLive isHostShowAlert:NO];
  1097. }
  1098. }
  1099. #pragma mark 切换付费
  1100. - (void)clickChangePay:(TCShowLiveView *)showLiveView
  1101. {
  1102. if ([[self.currentMonitorDict objectForKey:@"live"] toInt:@"allow_live_pay"] == 1)
  1103. {
  1104. [self.livePay creatPriceViewWithCount:1];
  1105. }
  1106. else
  1107. {
  1108. [FanweMessage alert:ASLocalizedString(@"直播间人数未达到收费人数")];
  1109. }
  1110. }
  1111. #pragma mark 提档
  1112. - (void)clickMention:(TCShowLiveView *)showLiveView
  1113. {
  1114. if ([[self.currentMonitorDict objectForKey:@"live"] toInt:@"allow_mention"] == 1)
  1115. {
  1116. [self.livePay creatPriceViewWithCount:2];
  1117. }
  1118. }
  1119. - (void)changePayView:(TCShowLiveView *)showLiveView
  1120. {
  1121. [self.livePay changeLeftViewFrameWithIsHost:_isHost andAuctionView:showLiveView.topView.priceView andBankerView:showLiveView.gameBankerView];
  1122. }
  1123. - (void)changePayViewFrame:(TCShowLiveView *)showLiveView
  1124. {
  1125. [self.livePay changeLeftViewFrameWithIsHost:_isHost andAuctionView:showLiveView.topView.priceView andBankerView:showLiveView.gameBankerView];
  1126. }
  1127. - (void)dealLivepayTComfirm
  1128. {
  1129. self.livePay.audienceLeftPView.hidden = NO;//观众进入直播间要把左边的付费信息显示出来(一开始为了避免预览倒计时和左边重叠就将其隐藏)
  1130. [self.livePayTimer invalidate];
  1131. self.livePayTimer = nil;
  1132. [self.livePayLabel removeFromSuperview];
  1133. self.livePayLabel = nil;
  1134. }
  1135. #pragma mark - ----------------------- 键盘事件 -----------------------
  1136. #pragma mark 键盘监听
  1137. - (void)registerKeyBoardNotification
  1138. {
  1139. //添加键盘监听
  1140. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onKeyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  1141. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onKeyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  1142. FWWeakify(self)
  1143. // 1.监听键盘 地球 切换
  1144. [Noti_Default addObserverForName:UIKeyboardDidChangeFrameNotification
  1145. object:nil
  1146. queue:[NSOperationQueue mainQueue]
  1147. usingBlock:^(NSNotification *_Nonnull note) {
  1148. FWStrongify(self)
  1149. // 取出键盘高度
  1150. CGRect keyboardF = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  1151. CGFloat keyboardH = keyboardF.size.height;
  1152. if (self.isKeyboardTypeNum == 1 && self.isHaveHalfIMMsgVC)
  1153. {
  1154. for (UIViewController *one_VC in self.childViewControllers)
  1155. {
  1156. if ([one_VC isKindOfClass:[BGConversationServiceController class]])
  1157. {
  1158. BGConversationServiceController *im_Msg_VC = (BGConversationServiceController *) one_VC;
  1159. [UIView animateWithDuration:0.25
  1160. animations:^{
  1161. im_Msg_VC.view.y = kScreenH / 2 - keyboardH;
  1162. }
  1163. completion:^(BOOL finished){
  1164. }];
  1165. }
  1166. }
  1167. }
  1168. }];
  1169. }
  1170. - (void)onKeyboardWillShow:(NSNotification *)notification
  1171. {
  1172. // 1.键盘弹出需要的时间
  1173. CGFloat animationDuration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
  1174. // 取出键盘高度
  1175. CGRect keyboardF = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  1176. CGFloat keyboardH = keyboardF.size.height;
  1177. FWWeakify(self)
  1178. [UIView animateWithDuration:animationDuration animations:^{
  1179. FWStrongify(self)
  1180. if (_isHaveHalfIMMsgVC == YES && _isKeyboardTypeNum != 1)
  1181. {
  1182. // 弹出 文本 键盘
  1183. //[self textKeyboardUp:keyboardH];
  1184. }
  1185. if (self.isHaveHalfIMChatVC == NO )
  1186. {
  1187. if (self.liveView.goldFlowerView && self.liveView.goldViewCanNotSee == NO && self.liveView.bankerViewCanSee == NO)
  1188. {
  1189. self.liveView.liveInputView.transform = CGAffineTransformMakeTranslation(0, -keyboardH+self.liveView.goldFlowerViewHeiht);
  1190. self.liveView.msgView.transform = CGAffineTransformMakeTranslation(0, -keyboardH+self.liveView.goldFlowerViewHeiht);
  1191. // [self textKeyboardUp:keyboardH];
  1192. }
  1193. else if (self.liveView.guessSizeView && self.liveView.guessSizeViewCanNotSee == NO && self.liveView.bankerViewCanSee == NO)
  1194. {
  1195. self.liveView.liveInputView.transform = CGAffineTransformMakeTranslation(0, -keyboardH+kGuessSizeViewHeight);
  1196. self.liveView.msgView.transform = CGAffineTransformMakeTranslation(0, -keyboardH+kGuessSizeViewHeight);
  1197. //[self textKeyboardUp:keyboardH];
  1198. }
  1199. else if ((self.liveView.goldFlowerView || self.liveView.guessSizeView) && self.liveView.bankerViewCanSee == YES)
  1200. {
  1201. // _liveView.bankerView.y = _liveView.height - keyboardF.size.height - _liveView.bankerView.height - 50;
  1202. }
  1203. else
  1204. {
  1205. // self.liveView.transform = CGAffineTransformMakeTranslation(0, - keyboardH);
  1206. [UIView animateWithDuration:animationDuration animations:^{
  1207. self.liveView.liveInputView.top = kScreenH - keyboardH - self.liveView.liveInputView.height;
  1208. }];
  1209. }
  1210. }
  1211. }];
  1212. }
  1213. #pragma mark 弹起文本键盘
  1214. - (void)textKeyboardUp:(CGFloat)move_high
  1215. {
  1216. for (UIViewController *vc in self.childViewControllers)
  1217. {
  1218. if ([vc isKindOfClass:[BGConversationServiceController class]])
  1219. {
  1220. BGConversationServiceController *im_Msg_VC = (BGConversationServiceController *) vc;
  1221. FWWeakify(self)
  1222. __weak BGConversationServiceController *imMsgVC = im_Msg_VC;
  1223. _isKeyboardTypeNum = 1;
  1224. //关闭
  1225. CGFloat time = 0.0;
  1226. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(time * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1227. // 保证表情
  1228. if(move_high <100)
  1229. {
  1230. return ;
  1231. }
  1232. [UIView animateWithDuration:0.4 animations:^{
  1233. //im_Msg_VC.view.height = kScreenH/2;
  1234. imMsgVC.view.y = kScreenH/2-move_high;
  1235. } completion:^(BOOL finished) {
  1236. FWStrongify(self)
  1237. //必须写在这里
  1238. if (finished)
  1239. {
  1240. imMsgVC.view.height = kScreenH/2;
  1241. imMsgVC.view.y = kScreenH/2-move_high;
  1242. imMsgVC.inputView.hidden = YES;
  1243. self.isKeyboardTypeNum = 1;//是否加载半屏幕 VC 键盘类型 1文本 2表情 3更多
  1244. }
  1245. }];
  1246. });
  1247. }
  1248. }
  1249. }
  1250. - (void)onKeyboardDidShow:(NSNotification *)notification
  1251. {
  1252. }
  1253. - (void)onKeyboardWillHide:(NSNotification *)notification
  1254. {
  1255. self.liveView.bottomView.hidden = NO;
  1256. [self.liveView hideInputView];
  1257. // 1.键盘弹出需要的时间
  1258. CGFloat duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
  1259. // 取出键盘高度
  1260. CGRect keyboardF = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  1261. CGFloat keyboardH = keyboardF.size.height;
  1262. FWWeakify(self)
  1263. // 2.动画
  1264. [UIView animateWithDuration:duration animations:^{
  1265. FWStrongify(self)
  1266. if (_isHaveHalfIMMsgVC == YES)
  1267. {
  1268. [[NSNotificationCenter defaultCenter] postNotificationName:@"HalfIMMsgChaVC" object:nil userInfo:@{@"keyboardH":[NSString stringWithFormat:@"%f",keyboardH]}];
  1269. return ;
  1270. }
  1271. if (self.isHaveHalfIMChatVC == NO)
  1272. {
  1273. if (self.liveView.goldFlowerView && self.liveView.goldViewCanNotSee == NO && self.liveView.bankerViewCanSee == NO)
  1274. {
  1275. self.liveView.liveInputView.transform = CGAffineTransformIdentity;//恢复之前的位置
  1276. self.liveView.msgView.transform = CGAffineTransformIdentity;//恢复之前的位置
  1277. self.liveView.transform = CGAffineTransformIdentity;//恢复之前的位置
  1278. }
  1279. else if (self.liveView.guessSizeView && self.liveView.guessSizeViewCanNotSee == NO && self.liveView.bankerViewCanSee == NO)
  1280. {
  1281. self.liveView.liveInputView.transform = CGAffineTransformIdentity;//恢复之前的位置
  1282. self.liveView.msgView.transform = CGAffineTransformIdentity;//恢复之前的位置
  1283. self.liveView.transform = CGAffineTransformIdentity;//恢复之前的位置
  1284. }
  1285. else if ((self.liveView.goldFlowerView || self.liveView.guessSizeView) && self.liveView.bankerViewCanSee == YES)
  1286. {
  1287. // self.liveView.bankerView.frame = CGRectMake((kScreenW - 255)/2, (kScreenH - 195)/2, 255, 195);
  1288. }
  1289. else
  1290. {
  1291. // self.liveView.transform = CGAffineTransformIdentity;//恢复之前的位置
  1292. [UIView animateWithDuration:duration animations:^{
  1293. self.liveView.liveInputView.top = kScreenH;
  1294. }];
  1295. }
  1296. [self.liveView relayoutFrameOfSubViews];
  1297. }
  1298. }];
  1299. }
  1300. #pragma mark -表情/更多 键盘弹起
  1301. /*!
  1302. * @author Yue
  1303. *
  1304. * @brief ykk825 代理实现 表情/更多按钮控制 键盘弹起
  1305. *
  1306. * @param isFace 表情
  1307. * @param isHave 键盘是否已经存在
  1308. *
  1309. * @step 1: 表情键盘
  1310. *
  1311. *
  1312. */
  1313. - (void)faceAndMoreKeyboardBtnClickWith:(BOOL)isFace isNotHaveBothKeyboard:(BOOL)isHave keyBoardHeight:(CGFloat)height
  1314. {
  1315. for (UIViewController *vc in self.childViewControllers)
  1316. {
  1317. if ([vc isKindOfClass:[BGConversationServiceController class]])
  1318. {
  1319. BGConversationServiceController *imMsg_VC = (BGConversationServiceController *) vc;
  1320. [UIView animateWithDuration:0.2 animations:^{
  1321. if(isHave == YES)
  1322. {
  1323. imMsg_VC.view.y = kScreenH/2-300;
  1324. imMsg_VC.view.height = kScreenH-(kScreenH*0.5-300)-height;
  1325. }
  1326. else if (isFace == YES)
  1327. {
  1328. imMsg_VC.view.y = kScreenH/2-300;
  1329. imMsg_VC.view.height = kScreenH-(kScreenH*0.5-300);
  1330. }
  1331. else if (isHave == NO && isFace == NO)
  1332. {
  1333. imMsg_VC.view.y = kScreenH/2;
  1334. imMsg_VC.view.height =kScreenH/2;
  1335. }
  1336. else
  1337. {
  1338. imMsg_VC.view.y = kScreenH/2;
  1339. }
  1340. } completion:^(BOOL finished) {
  1341. }];
  1342. }
  1343. }
  1344. }
  1345. #pragma mark - ----------------------- 弹出 半屏幕VC 部分 -----------------------
  1346. /**
  1347. 直播VC 加2个子 半屏幕的子VC
  1348. 不能直接的push/模态。。弹出半VC,直播VC 还要能点击--加载/退出分2部分: 导航上按钮控制 & 其他控件控制
  1349. 1: 添加chatVC 列表Vc
  1350. 2: chatVC 返回键
  1351. 3: chatVC 点击cell 加载 到 IMMsgVC
  1352. 4: IMMsgVC 返回按键 返回到 chatVC
  1353. 5: homePageVC IMMsgVC push homePageVC
  1354. 6: clickBlank 实现代理方法,是TCShowLieView 的方法(手势里
  1355. 7: returnChatVC 找到子VC-chatVC
  1356. 8: returnIMMsgVC 找到子VC -IMMsgVC
  1357. */
  1358. - (void)addTwoSubVC
  1359. {
  1360. if (!_imChatVCBgView)
  1361. {
  1362. _imChatVCBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  1363. _imChatVCBgView.backgroundColor = [UIColor clearColor];
  1364. [self.liveView addSubview:_imChatVCBgView];
  1365. UITapGestureRecognizer *IMChatVCTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ChatVCBgViewTap)];
  1366. [_imChatVCBgView addGestureRecognizer:IMChatVCTap];
  1367. }
  1368. else
  1369. {
  1370. _imChatVCBgView.hidden = NO;
  1371. }
  1372. //1.
  1373. if (self.isHaveHalfIMChatVC == YES)
  1374. {
  1375. return;
  1376. }
  1377. //2.
  1378. //ConversationListController *imChat_VC = [ConversationListController createIMChatVCWithHalf:self isRelive:NO];
  1379. BGConversationSegmentController *imChat_VC = [BGConversationSegmentController createIMChatVCWithHalf:self isRelive:NO];
  1380. //3.
  1381. _isKeyboardTypeNum = 0;
  1382. self.isHaveHalfIMChatVC = YES;
  1383. //4.
  1384. __weak __typeof(self) weak_Self = self;
  1385. __weak BGConversationSegmentController *weak_chat_VC = imChat_VC;
  1386. //5.
  1387. weak_chat_VC.goNextVCBlock = ^(int tag, SFriendObj *friend_Obj) {
  1388. //6.
  1389. if (tag == 1)
  1390. {
  1391. [weak_Self chatVCBackToLiveVC:weak_chat_VC];
  1392. }
  1393. else
  1394. {
  1395. //7.去聊天界面
  1396. if (weak_Self.isHaveHalfIMMsgVC == YES)
  1397. {
  1398. return;
  1399. }
  1400. //8.Go
  1401. [weak_Self chatVCGoIMMsgVC:weak_chat_VC withFrinend:friend_Obj];
  1402. }
  1403. };
  1404. }
  1405. #pragma mark -chatVC -返回
  1406. //@step 2:
  1407. - (void)chatVCBackToLiveVC:(BGConversationSegmentController *)chat_VC
  1408. {
  1409. // A --返回 chatVC -- 直接移到下面 并删除
  1410. [UIView animateWithDuration:kHalfVCViewanimation animations:^{
  1411. //当前chatVc 半VC 显示,要下去
  1412. chat_VC.view.y = kScreenH;
  1413. } completion:^(BOOL finished) {
  1414. //移除 chatVc
  1415. [chat_VC.view removeFromSuperview];
  1416. [self removeChild:chat_VC];
  1417. self.isHaveHalfIMChatVC = NO;
  1418. self.isHaveHalfIMMsgVC = NO;
  1419. }];
  1420. }
  1421. #pragma mark - Goto 聊天 half VC
  1422. //@step 3:
  1423. - (void)chatVCGoIMMsgVC:(BGConversationSegmentController *)chat_VC withFrinend:(SFriendObj *)friend_Obj
  1424. {
  1425. BGConversationServiceController *imMsgChat_VC = [[BGConversationServiceController alloc] initWithNibName:@"BGBaseChatController"
  1426. bundle:nil];
  1427. //1.2
  1428. imMsgChat_VC.mbhalf = NO;
  1429. imMsgChat_VC.mChatFriend = friend_Obj;
  1430. //1.1
  1431. // imMsgChat_VC.view.frame = CGRectMake(kScreenW, kScreenH / 2, kScreenW, kScreenH / 2 );
  1432. [[AppDelegate sharedAppDelegate] pushViewController:imMsgChat_VC animated:NO];
  1433. return;
  1434. // BGConversationServiceController *imMsgChat_VC = [BGConversationServiceController createIMMsgVCWithHalfWith:friend_Obj form:self isRelive:NO];
  1435. // imMsgChat_VC.delegate = self;
  1436. // self.isHaveHalfIMMsgVC = YES;
  1437. // // 传一个参数
  1438. // __weak BGConversationServiceController *weak_iMsg_VC = imMsgChat_VC;
  1439. // weak_iMsg_VC.backOrGoNextVCBlock = ^(int tag) {
  1440. // // 返回到chatVC
  1441. // if (tag == 1)
  1442. // {
  1443. // [self imMsgVcGoBackToChatVC:weak_iMsg_VC];
  1444. // }
  1445. // else
  1446. // {
  1447. // //去 push
  1448. // [self imMsgVCPushHomePageVC:weak_iMsg_VC];
  1449. // }
  1450. // };
  1451. }
  1452. #pragma - imMsgVC - 聊天返回列表ChatVC
  1453. //@step 4:
  1454. - (void)imMsgVcGoBackToChatVC:(BGConversationServiceController *)weak_iMsg_VC
  1455. {
  1456. //先下来 表情/更多
  1457. CGFloat time;
  1458. CGFloat height = weak_iMsg_VC.view.frame.size.height;
  1459. if (height > kScreenH/2)
  1460. {
  1461. time = 0.2;
  1462. weak_iMsg_VC.inputView.hidden = YES;
  1463. [UIView animateWithDuration:time animations:^{
  1464. weak_iMsg_VC.view.y =kScreenH/2;
  1465. } completion:^(BOOL finished) {
  1466. weak_iMsg_VC.view.height = kScreenH/2;
  1467. weak_iMsg_VC.inputView.hidden = NO;
  1468. self.isKeyboardTypeNum = 0;
  1469. }];
  1470. }
  1471. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(time * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1472. [UIView animateWithDuration:kHalfVCViewanimation animations:^{
  1473. weak_iMsg_VC.view.x = kScreenW;
  1474. } completion:^(BOOL finished) {
  1475. weak_iMsg_VC.view.height = kScreenH/2;
  1476. [weak_iMsg_VC.view removeFromSuperview];
  1477. [self removeChild:weak_iMsg_VC
  1478. animation:nil];
  1479. self.isHaveHalfIMMsgVC = NO;
  1480. }];
  1481. });
  1482. }
  1483. #pragma - imMsgVC - push 到个人中心
  1484. // @step 5:
  1485. - (void)imMsgVCPushHomePageVC:(BGConversationServiceController *)imMsgChatVC
  1486. {
  1487. SHomePageVC *tmpController = [[SHomePageVC alloc] init];
  1488. tmpController.user_id = [NSString stringWithFormat:@"%d", imMsgChatVC.mChatFriend.mUser_id];
  1489. tmpController.type = 0;
  1490. [imMsgChatVC.navigationController pushViewController:tmpController animated:YES];
  1491. }
  1492. #pragma mark 点击空白部分(半VC出现时)
  1493. - (void)ChatVCBgViewTap
  1494. {
  1495. //后期 通知要废掉
  1496. [[NSNotificationCenter defaultCenter] postNotificationName:@"imRemoveNeedUpdate" object:nil];
  1497. _imChatVCBgView.hidden = YES;
  1498. self.panGestureRec.enabled = YES;
  1499. for (UIViewController *one_VC in self.childViewControllers)
  1500. {
  1501. //chatVC 存在
  1502. if ([one_VC isKindOfClass:[BGConversationSegmentController class]])
  1503. {
  1504. BGConversationSegmentController *imChat_VC = (BGConversationSegmentController *) one_VC;
  1505. [UIView animateWithDuration:kHalfVCViewanimation
  1506. animations:^{
  1507. imChat_VC.view.y = kScreenH;
  1508. }
  1509. completion:^(BOOL finished) {
  1510. if (finished)
  1511. {
  1512. [imChat_VC.view removeFromSuperview];
  1513. [self removeChild:imChat_VC];
  1514. self.isHaveHalfIMChatVC = NO;
  1515. _isKeyboardTypeNum = 0;
  1516. }
  1517. }];
  1518. }
  1519. //聊天 退出
  1520. if ([one_VC isKindOfClass:[BGConversationServiceController class]])
  1521. {
  1522. BGConversationSegmentController *imMsgChat_VC = (BGConversationSegmentController *) one_VC;
  1523. [UIView animateWithDuration:kHalfVCViewanimation
  1524. animations:^{
  1525. imMsgChat_VC.view.y = kScreenH;
  1526. }
  1527. completion:^(BOOL finished) {
  1528. [imMsgChat_VC.view removeFromSuperview];
  1529. [self removeChild:imMsgChat_VC];
  1530. self.isHaveHalfIMMsgVC = NO;
  1531. _isKeyboardTypeNum = 0;
  1532. }];
  1533. }
  1534. }
  1535. }
  1536. #pragma mark - ----------------------- 滑动手势 -----------------------
  1537. #pragma mark - pan手势冲突
  1538. #pragma mark移除滑动手势 ? ? ?
  1539. #pragma mark pan手势冲突
  1540. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
  1541. {
  1542. if ([touch.view isKindOfClass:[BGTLiveScrollView class]]) {
  1543. return NO;
  1544. }
  1545. if ([touch.view isDescendantOfView:self.shopExplainView]) {
  1546. return NO;
  1547. }
  1548. if (SUS_WINDOW.isSmallSusWindow )
  1549. {
  1550. return NO;
  1551. }
  1552. else
  1553. {
  1554. return YES;
  1555. }
  1556. }
  1557. #pragma mark移除滑动手势
  1558. - (void)removePanGestureRec
  1559. {
  1560. if (_panGestureRec)
  1561. {
  1562. [_panGestureRec removeTarget:self action:@selector(moveViewWithGesture:)];
  1563. }
  1564. }
  1565. #pragma mark 设置当前是否能够使用滑动手势
  1566. - (void)setPanGesture:(BOOL)isEnabled
  1567. {
  1568. _panGestureRec.enabled = isEnabled;
  1569. }
  1570. #pragma mark 滑动手势
  1571. - (void)moveViewWithGesture:(UIPanGestureRecognizer *)panGes
  1572. {
  1573. if (_fpkProgress) {
  1574. // [FanweMessage alertHUD:ASLocalizedString(@"pk中不能滑动直播间!")];
  1575. return;
  1576. }
  1577. if ([GlobalVariables sharedInstance].isBeingLinkMic) {
  1578. // [FanweMessage alertHUD:ASLocalizedString(@"连麦中不能滑动直播间!")];
  1579. return;
  1580. }
  1581. // 关闭键盘
  1582. [BGUtils closeKeyboard];
  1583. //ykk 半VC 出现 禁止滑动live—View
  1584. if (self.isHaveHalfIMChatVC == YES || self.isHaveHalfIMMsgVC == YES)
  1585. {
  1586. panGes.enabled = NO;
  1587. return;
  1588. }
  1589. else
  1590. {
  1591. panGes.enabled = YES;
  1592. }
  1593. if (!_isHost)
  1594. {
  1595. static CGFloat startX;
  1596. static CGFloat lastX;
  1597. static CGFloat startY;
  1598. static CGFloat lastY;
  1599. static CGFloat durationX;
  1600. static CGFloat durationY;
  1601. CGPoint touchPoint = [panGes locationInView:[[UIApplication sharedApplication] keyWindow]];
  1602. if (panGes.state == UIGestureRecognizerStateBegan)
  1603. {
  1604. startX = touchPoint.x;
  1605. lastX = touchPoint.x;
  1606. startY = touchPoint.y;
  1607. lastY = touchPoint.y;
  1608. }
  1609. if (panGes.state == UIGestureRecognizerStateChanged)
  1610. {
  1611. CGFloat currentX = touchPoint.x;
  1612. durationX = currentX - lastX;
  1613. lastX = currentX;
  1614. CGFloat currentY = touchPoint.y;
  1615. durationY = currentY - lastY;
  1616. lastY = currentY;
  1617. NSLog(@"durationX%f",durationX);
  1618. NSLog(@"durationY%f",durationY);
  1619. //验证滑动手势朝左右方向大还是朝上下方向大
  1620. //朝左右方向滑动
  1621. if (fabs(durationX) > fabs(durationY))
  1622. {
  1623. //如果正在上下滑动就不能左右滑动
  1624. if (self.view.frame.origin.y > 0 || CGRectGetMaxY(self.view.frame) < self.view.frame.size.height)
  1625. {
  1626. return;
  1627. }
  1628. _isLeftOrRightPan = YES;
  1629. if (durationX > 0)
  1630. {
  1631. _isFromeLeft = YES;
  1632. }
  1633. else if (durationX < 0)
  1634. {
  1635. _isFromeLeft = NO;
  1636. }
  1637. if (self.liveView.frame.origin.x <= 0 && !_isFromeLeft)
  1638. {
  1639. return;
  1640. }
  1641. if (!_showingRight)
  1642. {
  1643. _showingRight = YES;
  1644. }
  1645. float x = durationX + self.liveView.frame.origin.x;
  1646. NSLog(@"left right%f",x);
  1647. [self.liveView setFrame:CGRectMake(x, self.liveView.frame.origin.y, self.liveView.frame.size.width, self.liveView.frame.size.height)];
  1648. }
  1649. else{//朝上下方向滑动
  1650. return;;
  1651. if (_fpkProgress) {
  1652. // [FanweMessage alertHUD:ASLocalizedString(@"pk中不能滑动直播间!")];
  1653. return;
  1654. }
  1655. if (durationY>0)
  1656. {
  1657. _isFromeTop = YES;
  1658. }
  1659. else if(durationY<0)
  1660. {
  1661. _isFromeTop = NO;
  1662. }
  1663. _isLeftOrRightPan = NO;
  1664. self.liveScrollView.top = durationY + self.liveScrollView.top;
  1665. NSLog(@"durationY%f",self.liveScrollView.top);
  1666. self.liveScrollView.isFromeTop = _isFromeTop;
  1667. float scrollDuration = fabs(durationY);
  1668. // self.liveScrollView.top - kScreenH);
  1669. BOOL isRefresh = scrollDuration > kScreenH * BEGIN_SLIDE_RATE2;
  1670. NSLog(@"%f",scrollDuration);
  1671. NSLog(@"kScreenH * BEGIN_SLIDE_RATE2 %f",kScreenH * BEGIN_SLIDE_RATE2);
  1672. NSLog(@"%d",isRefresh);
  1673. if (self.serviceDelegate && [self.serviceDelegate respondsToSelector:@selector(protocolDidScrollView:isRefreshLive:)]) {
  1674. [self.serviceDelegate protocolDidScrollView:self.liveScrollView isRefreshLive:isRefresh];
  1675. }
  1676. }
  1677. }
  1678. else if (panGes.state == UIGestureRecognizerStateEnded)
  1679. {
  1680. // if (self.liveScrollView.top != 0 || self.liveScrollView.top != kScreenH || self.liveScrollView.top != kScreenH * 2) {
  1681. // _isLeftOrRightPan = NO;
  1682. // }
  1683. if (_isLeftOrRightPan)
  1684. { //朝左右方向滑动
  1685. if (_showingRight)
  1686. {
  1687. if (_isFromeLeft)
  1688. {
  1689. if (self.liveView.frame.origin.x < self.view.frame.size.width * BEGIN_SLIDE_RATE)
  1690. {
  1691. float durationTime = (self.liveView.frame.origin.x) / (self.view.frame.size.width) / DURING_TIME;
  1692. [UIView animateWithDuration:durationTime
  1693. animations:^{
  1694. [self.liveView setFrame:CGRectMake(0, self.liveView.frame.origin.y, self.liveView.frame.size.width, self.liveView.frame.size.height)];
  1695. }
  1696. completion:^(BOOL finished) {
  1697. self.liveView.userInteractionEnabled = YES;
  1698. }];
  1699. }
  1700. else
  1701. {
  1702. float durationTime = (1 - (self.liveView.frame.origin.x) / (self.view.frame.size.width)) / DURING_TIME;
  1703. [UIView animateWithDuration:durationTime
  1704. animations:^{
  1705. [self.liveView setFrame:CGRectMake(self.view.frame.size.width, self.liveView.frame.origin.y, self.liveView.frame.size.width, self.liveView.frame.size.height)];
  1706. }
  1707. completion:^(BOOL finished) {
  1708. [self.view sendSubviewToBack:self.liveView];
  1709. _showingRight = NO;
  1710. }];
  1711. }
  1712. }
  1713. else
  1714. {
  1715. if (self.liveView.frame.origin.x < self.view.frame.size.width * (1 - BEGIN_SLIDE_RATE))
  1716. {
  1717. float durationTime = (self.liveView.frame.origin.x) / (self.view.frame.size.width) / DURING_TIME;
  1718. [UIView animateWithDuration:durationTime
  1719. animations:^{
  1720. [self.liveView setFrame:CGRectMake(0, self.liveView.frame.origin.y, self.liveView.frame.size.width, self.liveView.frame.size.height)];
  1721. }
  1722. completion:^(BOOL finished) {
  1723. self.liveView.userInteractionEnabled = YES;
  1724. }];
  1725. }
  1726. else
  1727. {
  1728. float durationTime = (1 - (self.liveView.frame.origin.x) / (self.view.frame.size.width)) / DURING_TIME;
  1729. [UIView animateWithDuration:durationTime
  1730. animations:^{
  1731. [self.liveView setFrame:CGRectMake(self.view.frame.size.width, self.liveView.frame.origin.y, self.liveView.frame.size.width, self.liveView.frame.size.height)];
  1732. }
  1733. completion:^(BOOL finished) {
  1734. [self.view sendSubviewToBack:self.liveView];
  1735. _showingRight = NO;
  1736. }];
  1737. }
  1738. }
  1739. }
  1740. }
  1741. else //朝上下方向滑动
  1742. {
  1743. return;
  1744. self.liveScrollView.isFromeTop = _isFromeTop;
  1745. BOOL isRefresh = YES;
  1746. self.liveScrollView.y = self.liveScrollView.isFromeTop ? 0 : kScreenH;
  1747. if (self.serviceDelegate && [self.serviceDelegate respondsToSelector:@selector(protocolDidScrollView:isRefreshLive:)]) {
  1748. [self.serviceDelegate protocolDidScrollView:self.liveScrollView isRefreshLive:isRefresh];
  1749. }
  1750. // return;
  1751. //
  1752. // if (self.liveScrollView.y < kScreenH)
  1753. // {
  1754. // self.liveScrollView.y = self.liveScrollView.y < kScreenH * BEGIN_SLIDE_RATE2 ? 0 : kScreenH;
  1755. //
  1756. // if (self.serviceDelegate && [self.serviceDelegate respondsToSelector:@selector(protocolDidScrollView:isRefreshLive:)]) {
  1757. // [self.serviceDelegate protocolDidScrollView:self.liveScrollView isRefreshLive:isRefresh];
  1758. // }
  1759. // return;
  1760. // }
  1761. // if (self.liveScrollView.y < (kScreenH * 2)) {
  1762. // self.liveScrollView.y = self.liveScrollView.y < kScreenH * BEGIN_SLIDE_RATE2 ? kScreenH : kScreenH * 2;
  1763. // if (self.serviceDelegate && [self.serviceDelegate respondsToSelector:@selector(protocolDidScrollView:isRefreshLive:)]) {
  1764. // [self.serviceDelegate protocolDidScrollView:self.liveScrollView isRefreshLive:isRefresh];
  1765. // }
  1766. // return;
  1767. // }
  1768. // if (self.liveScrollView.y < (kScreenH * 3)) {
  1769. // self.liveScrollView.y = self.liveScrollView.y < kScreenH * BEGIN_SLIDE_RATE2 ? kScreenH * 2 : kScreenH * 3;
  1770. // if (self.serviceDelegate && [self.serviceDelegate respondsToSelector:@selector(protocolDidScrollView:isRefreshLive:)]) {
  1771. // [self.serviceDelegate protocolDidScrollView:self.liveScrollView isRefreshLive:isRefresh];
  1772. // }
  1773. // return;
  1774. // }
  1775. }
  1776. }
  1777. }
  1778. }
  1779. #pragma mark - scrollview的代理方法
  1780. -(void)scrollViewDidScroll:(BGTLiveScrollView *)scrollView{
  1781. if (self.serviceDelegate && [self.serviceDelegate respondsToSelector:@selector(protocolDidScrollView:isRefreshLive:)]) {
  1782. [self.serviceDelegate protocolDidScrollView:self.liveScrollView isRefreshLive:NO];
  1783. }
  1784. }
  1785. -(BogoShopExplainView *)shopExplainView{
  1786. if (!_shopExplainView) {
  1787. _shopExplainView = [kShopKitBundle loadNibNamed:@"BogoShopExplainView" owner:nil options:nil].lastObject;
  1788. // _shopExplainView.delegate = self;
  1789. _shopExplainView.frame = CGRectMake(kScreenW - kRealValue(12) - kRealValue(130), kScreenHeight - MG_BOTTOM_MARGIN - kRealValue(50) - kRealValue(174), kRealValue(130), kRealValue(174));
  1790. _shopExplainView.clickBuyBlock = ^(BogoCommodityDetailShopModel * _Nonnull model) {
  1791. //送出 没有,没有点击事件
  1792. if (model.model_id.integerValue == 1) {
  1793. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:model.link_url]];
  1794. }else{
  1795. BogoGoodDetailViewController *detailVC = [[BogoGoodDetailViewController alloc]init];
  1796. detailVC.gid = model.gid;
  1797. // detailVC.distribution_id = model.distribution_uid;
  1798. detailVC.uid = model.uid;
  1799. detailVC.source = BogoShopBuySourceLive;
  1800. [self.navigationController pushViewController:detailVC animated:YES];
  1801. }
  1802. // _shopExplainView.duringDragBlock = ^(WMDragView *dragView) {
  1803. // _shopExplainView.frame = dragView.frame;
  1804. // };
  1805. // _shopExplainView.endDragBlock = ^(WMDragView *dragView) {
  1806. //
  1807. // CGContextRef context = UIGraphicsGetCurrentContext();
  1808. // [UIView beginAnimations:@"rightMove" context:context];
  1809. // [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
  1810. // [UIView setAnimationDuration:0.5];
  1811. //
  1812. // _shopExplainView.frame = dragView.frame;
  1813. //
  1814. // [UIView commitAnimations];
  1815. // };
  1816. };
  1817. // _shopExplainView.hidden = YES;
  1818. }
  1819. _shopExplainView.backgroundColor = kWhiteColor;
  1820. return _shopExplainView;
  1821. }
  1822. - (void)showFace
  1823. {
  1824. NSLog(@"点击了表情");
  1825. [self.faceView show:self.view];
  1826. }
  1827. - (void)showMusic
  1828. {
  1829. if(_musicVC == nil)
  1830. {
  1831. NSLog(@"点击了音乐");
  1832. _musicVC = [[choseMuiscVC alloc] init];
  1833. // _musicVC.delegate = self;
  1834. [self addChild:_musicVC inRect:CGRectMake(0, 227, SCREEN_WIDTH, SCREEN_HEIGHT-227)];
  1835. }
  1836. else
  1837. {
  1838. _musicVC.view.hidden = NO;
  1839. }
  1840. _musicVC.mitblock = ^(musiceModel *chosemusic) {
  1841. // [self removeChild:_musicVC];
  1842. _musicVC.view.hidden = YES;
  1843. };
  1844. // [choseMuiscVC showMuisChoseVCOnSuperVC:self inSuperView:self.view frame:CGRectMake(0, 227, SCREEN_WIDTH, SCREEN_HEIGHT-227) completion:^(BOOL finished) {
  1845. //
  1846. // }];
  1847. }
  1848. - (RoomFaceView *)faceView{
  1849. if (!_faceView) {
  1850. _faceView = [[RoomFaceView alloc]initWithFrame:CGRectMake(0, kScreenH, kScreenW, 320 + (IPHONE_X ? 34 : 0))];
  1851. _faceView.delegate = self;
  1852. }
  1853. return _faceView;
  1854. }
  1855. - (void)faceView:(RoomFaceView *)faceView didSelectFace:(RoomFaceModel *)model
  1856. {
  1857. [faceView hide];
  1858. if (self.serviceDelegate && [self.serviceDelegate respondsToSelector:@selector(protocolDidClickEmoji:)]) {
  1859. [self.serviceDelegate protocolDidClickEmoji:model.img];
  1860. }
  1861. // - (void)protocolDidClickEmoji:(NSString *)emoji;
  1862. }
  1863. //-(void)playMusicClicked:(musiceModel *)model
  1864. //{
  1865. //
  1866. //}
  1867. //
  1868. //- (void)stopMusic
  1869. //{
  1870. //
  1871. //}
  1872. //#pragma mark - RoomFaceViewDelegate
  1873. //- (void)faceView:(RoomFaceView *)faceView didSelectFace:(RoomFaceModel *)model{
  1874. // if (self.delegate && [self.delegate respondsToSelector:@selector(uicontroller:faceView:didSelectFace:)]) {
  1875. // [self.delegate uicontroller:self faceView:faceView didSelectFace:model];
  1876. // }
  1877. //}
  1878. @end