SearchDeviceViewController.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. //
  2. // SearchDeviceViewController.m
  3. // Unity-iPhone
  4. //
  5. // Created by duowan123 on 2021/2/4.
  6. //
  7. #import "SearchDeviceViewController.h"
  8. /*************************** 获取屏幕 宽度、高度 ***************************/
  9. #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
  10. #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
  11. @interface SearchDeviceViewController ()<UITableViewDelegate,UITableViewDataSource>
  12. @property(nonatomic,strong)UIView * bgView;//背景view
  13. @property(nonatomic,strong)UILabel * titleLabel;//
  14. @property(nonatomic,strong)UIView * line;//
  15. @property(nonatomic,strong)UIButton * closeButton;//
  16. @property(nonatomic,strong)UIButton * searchButton;//
  17. @property(nonatomic,strong)UIView * imageBGView;
  18. @property(nonatomic,strong)UIImageView * animationView;
  19. @property(nonatomic,strong)UIImageView * shoseimage;
  20. @end
  21. @implementation SearchDeviceViewController
  22. - (void)viewDidLoad{
  23. [super viewDidLoad];
  24. //创建需要的毛玻璃特效类型
  25. UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
  26. //创建毛玻璃视图
  27. UIVisualEffectView *visualV = [[UIVisualEffectView alloc] initWithEffect:blur];
  28. visualV.frame = self.view.bounds;
  29. //可以通过透明度来达到模糊程序的改变.
  30. visualV.effect = nil;
  31. visualV.backgroundColor = [UIColor blackColor];
  32. visualV.alpha = 0.5;
  33. [UIView animateWithDuration:1 animations:^{
  34. visualV.effect = blur;
  35. }];
  36. //把毛玻璃添加到view上
  37. [self.view addSubview:visualV];
  38. self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 320)];
  39. self.bgView.center = self.view.center;
  40. self.bgView.layer.masksToBounds = YES;
  41. self.bgView.layer.cornerRadius = 10;
  42. self.bgView.backgroundColor = [UIColor whiteColor];
  43. [self.view addSubview:self.bgView];
  44. [UIView animateWithDuration:0.8 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:0.3 options:0 animations:^{
  45. self.bgView.transform = CGAffineTransformIdentity;
  46. }completion:^(BOOL finished){
  47. }];
  48. self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 0, 200, 50)];
  49. self.titleLabel.text = @"选择鞋子";
  50. self.titleLabel.textAlignment = NSTextAlignmentCenter;
  51. [self.bgView addSubview:self.titleLabel];
  52. self.line = [[UIView alloc] initWithFrame:CGRectMake(5, 49, 300-10, .5)];
  53. self.line.backgroundColor = [UIColor lightGrayColor];
  54. [self.bgView addSubview:self.line];
  55. self.closeButton = [UIButton buttonWithType:UIButtonTypeSystem];
  56. self.closeButton.frame = CGRectMake(250, 0, 50, 50);
  57. [self.closeButton.titleLabel setTextColor:[UIColor darkGrayColor]];
  58. [self.closeButton setFont: [UIFont systemFontOfSize:15]];
  59. [self.closeButton setTitle:@"✖️" forState:UIControlStateNormal];
  60. [self.bgView addSubview:self.closeButton];
  61. [self.closeButton addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
  62. self.searchButton = [UIButton buttonWithType:UIButtonTypeSystem];
  63. self.searchButton.frame = CGRectMake(25, 270, 250, 40);
  64. [self.searchButton setTitle:@"搜索设备" forState:UIControlStateNormal];
  65. [self.searchButton setFont: [UIFont boldSystemFontOfSize: 13.0]];
  66. [self.searchButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  67. // [self.searchButton setBackgroundImage:[UIImage imageNamed:@"common_nornext_img"] forState:UIControlStateNormal];
  68. self.searchButton.backgroundColor = [UIColor colorWithRed:245.0/255 green:181.0/255 blue:66.0/255 alpha:1];
  69. self.searchButton.layer.masksToBounds = YES;
  70. self.searchButton.layer.cornerRadius = 20;
  71. [self.bgView addSubview:self.searchButton];
  72. self.searchButton.contentEdgeInsets = UIEdgeInsetsMake(0,0,.5, 0);
  73. [self.searchButton addTarget:self action:@selector(searchAction) forControlEvents:UIControlEventTouchUpInside];
  74. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50,300, 320-50-50-10) style:UITableViewStylePlain];
  75. self.tableView.delegate = self;
  76. self.tableView.dataSource = self;
  77. self.tableView.rowHeight = 70;
  78. self.tableView.showsVerticalScrollIndicator = NO;
  79. self.tableView.showsHorizontalScrollIndicator = NO;
  80. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  81. [self.bgView addSubview:self.tableView];
  82. self.animationView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 120, 120)];
  83. self.animationView.image = [self imageString:@"pop_image_circle"];
  84. // self.animationView.backgroundColor = [UIColor redColor];
  85. self.animationView.center = self.view.center;
  86. [self.view addSubview:self.animationView];
  87. [self.animationView bringSubviewToFront:self.view];
  88. self.shoseimage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 30)];
  89. self.shoseimage.image = [self imageString:@"pop_image_shoes"];
  90. // self.shoseimage.backgroundColor = [UIColor blueColor];
  91. self.shoseimage.center = self.view.center;
  92. [self.view addSubview:self.shoseimage];
  93. [self startAnimation];
  94. //
  95. }
  96. //正常加载还是打包后sdk加载
  97. -(UIImage*)imageString:(NSString*)imageName{
  98. BOOL ifSdk = NO;
  99. UIImage *orangeImage;
  100. if (ifSdk==YES){//打包成sdk后 加载imageUrl要用[self class]的方式
  101. NSBundle * refreshBundle = refreshBundle = [NSBundle bundleWithPath:[[NSBundle bundleForClass:[self class]] pathForResource:@"IOSUnityBundle" ofType:@"bundle"]];
  102. if (orangeImage == nil){
  103. orangeImage = [[UIImage imageWithContentsOfFile:[refreshBundle pathForResource:imageName ofType:@"png"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  104. }
  105. }else{
  106. orangeImage = [UIImage imageNamed:imageName];
  107. }
  108. return orangeImage;
  109. }
  110. //
  111. -(void)closeAction{
  112. [self close];
  113. }
  114. //
  115. -(void)searchAction{
  116. self.animationView.hidden = NO;
  117. self.shoseimage.hidden = NO;
  118. if(self.searchDeviceTask){
  119. self.searchDeviceTask();
  120. }
  121. }
  122. -(NSMutableArray*)deviceArray{
  123. if (!_deviceArray){
  124. _deviceArray = [NSMutableArray new];
  125. }
  126. return _deviceArray;
  127. }
  128. #pragma mark --------------------------------------------------- UITableViewDataSource
  129. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  130. // NSLog(@"数据源个数 = %ld",self.deviceArray.count);
  131. return self.deviceArray.count;
  132. }
  133. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  134. static NSString *identifier = @"deviceId";
  135. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  136. if (cell == nil) {
  137. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
  138. }
  139. CBPeripheral * peripheral = self.deviceArray[indexPath.row];
  140. // NSString *string = [self.deviceArray objectAtIndex:indexPath.row];
  141. cell.textLabel.text = peripheral.name;
  142. cell.detailTextLabel.text = peripheral.identifier.UUIDString;
  143. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  144. cell.selectionStyle = NO;
  145. return cell;
  146. }
  147. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  148. // [tableView deselectRowAtIndexPath:indexPath animated:YES];
  149. CBPeripheral * peripheral = self.deviceArray[indexPath.row];
  150. NSLog(@"self.deviceArray.index == %@",peripheral);
  151. if (self.connectDeviceBlock!=nil){
  152. self.connectDeviceBlock(peripheral);
  153. }
  154. [self close];
  155. [self close];
  156. }
  157. //-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  158. // return 44;
  159. //}
  160. //
  161. //-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  162. //
  163. // UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44)];
  164. // titleLabel.backgroundColor = BackGroundColor;
  165. // titleLabel.text = MyLocalizedString(@"Available Device");
  166. // titleLabel.textColor = NormalTextColor;
  167. // titleLabel.textAlignment = NSTextAlignmentCenter;
  168. // return titleLabel;
  169. //
  170. //}
  171. //- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  172. // [self close];
  173. //}
  174. - (void)close{
  175. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  176. [UIView animateWithDuration:0.25 animations:^{
  177. self.view.alpha = 0;
  178. [self.view removeFromSuperview];
  179. }completion:^(BOOL finished) {
  180. [self.view removeFromSuperview];
  181. }];
  182. });
  183. }
  184. - (void)startAnimation{
  185. [UIView animateWithDuration:1 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
  186. self.animationView.transform = CGAffineTransformRotate(self.animationView.transform,(M_PI/2.0));
  187. }completion:^(BOOL finished){
  188. [self startAnimation];
  189. }];
  190. }
  191. -(void)hideAnimation{
  192. self.animationView.hidden = YES;
  193. self.shoseimage.hidden = YES;
  194. }
  195. @end