FriendsListViewController.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. //
  2. // FriendsListViewController.m
  3. // Unity-iPhone
  4. //
  5. // Created by duowan123 on 2022/9/2.
  6. //
  7. #import "FriendsListViewController.h"
  8. #import "FriendsListView.h"
  9. @interface FriendsListViewController ()<FriendsListViewDelegate>
  10. //
  11. @property (strong, nonatomic)FriendsListView * friendsListCarouselView;
  12. //button
  13. @property(nonatomic,strong)UIButton * nextButton;//
  14. @property(nonatomic,strong)UIButton * lastButton;//
  15. @property(nonatomic,strong)UIButton * cancelButton;//
  16. @property(nonatomic,strong)UIButton * connectButton;//
  17. @property (nonatomic,strong)UIButton * clearnButton;//清理缓存
  18. //留白
  19. @property(nonatomic,strong)NoDeviceTip * tipView;
  20. @end
  21. @implementation FriendsListViewController
  22. -(void)viewDidLoad{
  23. [super viewDidLoad];
  24. [self initUI];
  25. }
  26. #pragma mark -- create UI
  27. -(void)initUI{
  28. //创建需要的毛玻璃特效类型
  29. UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
  30. //创建毛玻璃视图
  31. UIVisualEffectView *visualV = [[UIVisualEffectView alloc] initWithEffect:blur];
  32. visualV.frame = self.view.bounds;
  33. //可以通过透明度来达到模糊程序的改变.
  34. visualV.effect = nil;
  35. visualV.backgroundColor = [UIColor blackColor];
  36. visualV.alpha = 0.5;
  37. [UIView animateWithDuration:1 animations:^{
  38. visualV.effect = blur;
  39. }];
  40. [self.view addSubview:visualV];
  41. //无设备
  42. [self.view addSubview:self.tipView];
  43. //列表
  44. self.friendsListCarouselView = [[FriendsListView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-SCALEoefficient(200), SCREEN_HEIGHT-SCALEoefficient(100))];
  45. self.friendsListCarouselView.centerX = self.view.centerX;
  46. self.friendsListCarouselView.centerY = self.view.centerY-20;
  47. [self.view addSubview:self.friendsListCarouselView];
  48. self.friendsListCarouselView.delegate = self;
  49. //上一个
  50. self.nextButton = [UIButton buttonWithType:UIButtonTypeSystem];
  51. self.nextButton.frame = CGRectMake(0, 0, SCALEoefficient(16), SCALEoefficient(32));
  52. self.nextButton.centerY = self.friendsListCarouselView.centerY;
  53. self.nextButton.right = self.friendsListCarouselView.left+10;
  54. [self.nextButton setBackgroundImage:[MYFactoryManager imageString:@"gamepop_leftarrow"] forState:UIControlStateNormal];
  55. [self.view addSubview:self.nextButton];
  56. [self.nextButton addTarget:self action:@selector(lastAction) forControlEvents:UIControlEventTouchUpInside];
  57. self.nextButton.backgroundColor = [UIColor clearColor];
  58. //下一个
  59. self.lastButton = [UIButton buttonWithType:UIButtonTypeSystem];
  60. self.lastButton.frame = CGRectMake(0, 0, SCALEoefficient(16), SCALEoefficient(32));
  61. self.lastButton.centerY = self.friendsListCarouselView.centerY;
  62. self.lastButton.left = self.friendsListCarouselView.right-10;
  63. [self.lastButton setBackgroundImage:[MYFactoryManager imageString:@"gamepop_rihtarrow"] forState:UIControlStateNormal];
  64. [self.view addSubview:self.lastButton];
  65. [self.lastButton addTarget:self action:@selector(nextAction) forControlEvents:UIControlEventTouchUpInside];
  66. self.lastButton.backgroundColor = [UIColor clearColor];
  67. //关闭弹窗
  68. self.cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
  69. self.cancelButton.frame = CGRectMake(SCREEN_WIDTH-SCALEoefficient(100+20),SCALEoefficient(15), SCALEoefficient(100), SCALEoefficient(30));
  70. [self.cancelButton setTitle:@"左踮脚 · 返回" forState:UIControlStateNormal];
  71. [self.cancelButton setImage:[MYFactoryManager imageString:@"gamepop_close_notes"] forState:UIControlStateNormal];
  72. [self.cancelButton setFont: [UIFont boldSystemFontOfSize: SCALEoefficient(12)]];
  73. [self.cancelButton.titleLabel setTextColor:[UIColor whiteColor]];
  74. self.cancelButton.backgroundColor = [UIColor clearColor];
  75. [self.cancelButton setImageEdgeInsets:UIEdgeInsetsMake(0, SCALEoefficient(-10), 0, 0)];
  76. [self.cancelButton addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
  77. [self.view addSubview:self.cancelButton];
  78. //隐藏的清理缓存的按钮
  79. self.clearnButton = [UIButton buttonWithType:UIButtonTypeCustom];
  80. self.clearnButton.frame = CGRectMake(0, SCREEN_HEIGHT-SCALEoefficient(30)-SCALEoefficient(25), SCALEoefficient(60), SCALEoefficient(25));
  81. self.clearnButton.backgroundColor = [UIColor clearColor];
  82. [self.clearnButton addTarget:self action:@selector(clearCacheWithFilePath) forControlEvents:UIControlEventTouchUpInside];
  83. [self.view addSubview:self.clearnButton];
  84. NSArray * array = @[@"gamepop_leftarrow_notes",@"gamepop_rihgtarrow_notes",@"gamepop_determine_notes"];
  85. NSArray * titleArray = @[@"左踏 · 上一个",@"右踏 · 下一个",@"右踮脚 · 确认"];
  86. for (int i =0; i<3; i++){
  87. UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
  88. // button.frame = CGRectMake(SCREEN_WIDTH-SCALEoefficient(62+20+20)*(4-i),SCALEoefficient(23), SCALEoefficient(62+20), SCALEoefficient(20));
  89. button.frame = CGRectMake(SCREEN_WIDTH/3*i,SCREEN_HEIGHT-SCALEoefficient(30), SCREEN_WIDTH/3, SCALEoefficient(30));
  90. [button setTitle:titleArray[i] forState:UIControlStateNormal];
  91. [button setImage:[MYFactoryManager imageString:array[i]] forState:UIControlStateNormal];
  92. [button setFont: [UIFont boldSystemFontOfSize: SCALEoefficient(10)]];
  93. [button.titleLabel setTextColor:[UIColor whiteColor]];
  94. // button.tag = i;
  95. button.backgroundColor = [UIColor blackColor];
  96. [button setImageEdgeInsets:UIEdgeInsetsMake(0, SCALEoefficient(-10), 0, 0)];
  97. // [searchButton addTarget:self action:@selector(mapBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  98. [self.view addSubview:button];
  99. }
  100. }
  101. #pragma mark -------------- 外部事件
  102. //刷新蓝牙数据
  103. -(void)reloadData{
  104. if (self.friendsArray.count==0){
  105. self.tipView.hidden = NO;
  106. }else{
  107. self.tipView.hidden = YES;
  108. NSMutableArray * dataArr = [NSMutableArray new];
  109. for (int i = 0; i<self.friendsArray.count; i++){
  110. UserFriendsModel *model = [[UserFriendsModel alloc]init];
  111. NSDictionary * dict = self.friendsArray[i];
  112. NSDictionary * user = dict[@"user"];
  113. model.status = dict[@"status"];
  114. model.numberId = i;
  115. [model setValuesForKeysWithDictionary:user];
  116. [dataArr addObject:model];
  117. }
  118. [self.friendsListCarouselView setArrayData:dataArr];
  119. }
  120. }
  121. //蓝牙传过来的脚步交互动作
  122. -(void)getInteraction:(int)interaction{
  123. if (interaction == 0){//原地 -- 复位
  124. }else if(interaction == 3){//左踩 -- 选中上一个设备
  125. [self lastAction];
  126. }else if(interaction == 4){//右踩 -- 选中下一个设备
  127. [self nextAction];
  128. }else if(interaction == 6){//左垫脚 -- 关闭弹窗
  129. [self closeAction];
  130. }else if(interaction == 5){//右垫脚 -- 链接设备
  131. if (self.inviteFriendBlock){
  132. self.inviteFriendBlock(self.userFriendsModel);
  133. }
  134. [self closeAction];
  135. }
  136. }
  137. ////点击搜索按钮(暂留)
  138. //-(void)searchAction{
  139. //
  140. // self.tipView.hidden = NO;
  141. // if(self.searchDeviceTask){
  142. // [BTDataInstance initCBCentralManager];
  143. // }
  144. //
  145. //}
  146. #pragma mark -------------- 点击界面交互Action
  147. //选中上一个设备
  148. - (void)lastAction{
  149. [self.friendsListCarouselView yw_gotoNext:-1];
  150. }
  151. //选中下一个设备
  152. -(void)nextAction{
  153. [self.friendsListCarouselView yw_gotoNext:1];
  154. }
  155. //关闭弹窗
  156. - (void)closeAction{
  157. if (self.closeBlock){
  158. self.closeBlock();
  159. }
  160. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  161. [UIView animateWithDuration:0.25 animations:^{
  162. self.view.alpha = 0;
  163. [self.view removeFromSuperview];
  164. }completion:^(BOOL finished){
  165. [self.view removeFromSuperview];
  166. }];
  167. });
  168. }
  169. //清理缓存
  170. -(void)clearCacheWithFilePath{
  171. [DebugViewInstance clearCacheWithFilePath];
  172. }
  173. #pragma mark -------------- shoesCarouseView delegate
  174. -(void)setCurrentFriend:(UserFriendsModel*)model{
  175. self.userFriendsModel = model;
  176. }
  177. -(void)connectFriend:(UserFriendsModel*)model{
  178. self.userFriendsModel = model;
  179. //链接蓝牙
  180. if (self.inviteFriendBlock){
  181. self.inviteFriendBlock(self.userFriendsModel);
  182. }
  183. [self closeAction];
  184. }
  185. #pragma mark -------------- lazy
  186. -(NSMutableArray*)friendsArray{
  187. if (!_friendsArray){
  188. _friendsArray = [NSMutableArray new];
  189. }
  190. return _friendsArray;
  191. }
  192. -(NoDeviceTip*)tipView{
  193. if (!_tipView){
  194. _tipView = [[NoDeviceTip alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2-50, SCREEN_HEIGHT/2-100, 100, 150)];
  195. _tipView.centerY = self.friendsListCarouselView.centerY;
  196. _tipView.hidden = NO;
  197. }
  198. return _tipView;
  199. }
  200. @end