// // SearchDeviceViewController.m // Unity-iPhone // // Created by duowan123 on 2021/2/4. // #import "SearchDeviceViewController.h" /*************************** 获取屏幕 宽度、高度 ***************************/ #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width) #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height) @interface SearchDeviceViewController () @property(nonatomic,strong)UIView * bgView;//背景view @property(nonatomic,strong)UILabel * titleLabel;// @property(nonatomic,strong)UIView * line;// @property(nonatomic,strong)UIButton * closeButton;// @property(nonatomic,strong)UIButton * searchButton;// @property(nonatomic,strong)UIView * imageBGView; @property(nonatomic,strong)UIImageView * animationView; @property(nonatomic,strong)UIImageView * shoseimage; @end @implementation SearchDeviceViewController - (void)viewDidLoad{ [super viewDidLoad]; //创建需要的毛玻璃特效类型 UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; //创建毛玻璃视图 UIVisualEffectView *visualV = [[UIVisualEffectView alloc] initWithEffect:blur]; visualV.frame = self.view.bounds; //可以通过透明度来达到模糊程序的改变. visualV.effect = nil; visualV.backgroundColor = [UIColor blackColor]; visualV.alpha = 0.5; [UIView animateWithDuration:1 animations:^{ visualV.effect = blur; }]; //把毛玻璃添加到view上 [self.view addSubview:visualV]; self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 320)]; self.bgView.center = self.view.center; self.bgView.layer.masksToBounds = YES; self.bgView.layer.cornerRadius = 10; self.bgView.backgroundColor = [UIColor whiteColor]; [self.view addSubview:self.bgView]; [UIView animateWithDuration:0.8 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:0.3 options:0 animations:^{ self.bgView.transform = CGAffineTransformIdentity; }completion:^(BOOL finished){ }]; self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 0, 200, 50)]; self.titleLabel.text = @"选择鞋子"; self.titleLabel.textAlignment = NSTextAlignmentCenter; [self.bgView addSubview:self.titleLabel]; self.line = [[UIView alloc] initWithFrame:CGRectMake(5, 49, 300-10, .5)]; self.line.backgroundColor = [UIColor lightGrayColor]; [self.bgView addSubview:self.line]; self.closeButton = [UIButton buttonWithType:UIButtonTypeSystem]; self.closeButton.frame = CGRectMake(250, 0, 50, 50); [self.closeButton.titleLabel setTextColor:[UIColor darkGrayColor]]; [self.closeButton setFont: [UIFont systemFontOfSize:15]]; [self.closeButton setTitle:@"✖️" forState:UIControlStateNormal]; [self.bgView addSubview:self.closeButton]; [self.closeButton addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside]; self.searchButton = [UIButton buttonWithType:UIButtonTypeSystem]; self.searchButton.frame = CGRectMake(25, 270, 250, 40); [self.searchButton setTitle:@"搜索设备" forState:UIControlStateNormal]; [self.searchButton setFont: [UIFont boldSystemFontOfSize: 13.0]]; [self.searchButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; // [self.searchButton setBackgroundImage:[UIImage imageNamed:@"common_nornext_img"] forState:UIControlStateNormal]; self.searchButton.backgroundColor = [UIColor colorWithRed:245.0/255 green:181.0/255 blue:66.0/255 alpha:1]; self.searchButton.layer.masksToBounds = YES; self.searchButton.layer.cornerRadius = 20; [self.bgView addSubview:self.searchButton]; self.searchButton.contentEdgeInsets = UIEdgeInsetsMake(0,0,.5, 0); [self.searchButton addTarget:self action:@selector(searchAction) forControlEvents:UIControlEventTouchUpInside]; self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50,300, 320-50-50-10) style:UITableViewStylePlain]; self.tableView.delegate = self; self.tableView.dataSource = self; self.tableView.rowHeight = 70; self.tableView.showsVerticalScrollIndicator = NO; self.tableView.showsHorizontalScrollIndicator = NO; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; [self.bgView addSubview:self.tableView]; self.animationView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 120, 120)]; self.animationView.image = [self imageString:@"pop_image_circle"]; // self.animationView.backgroundColor = [UIColor redColor]; self.animationView.center = self.view.center; [self.view addSubview:self.animationView]; [self.animationView bringSubviewToFront:self.view]; self.shoseimage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 30)]; self.shoseimage.image = [self imageString:@"pop_image_shoes"]; // self.shoseimage.backgroundColor = [UIColor blueColor]; self.shoseimage.center = self.view.center; [self.view addSubview:self.shoseimage]; [self startAnimation]; // } //正常加载还是打包后sdk加载 -(UIImage*)imageString:(NSString*)imageName{ BOOL ifSdk = NO; UIImage *orangeImage; if (ifSdk==YES){//打包成sdk后 加载imageUrl要用[self class]的方式 NSBundle * refreshBundle = refreshBundle = [NSBundle bundleWithPath:[[NSBundle bundleForClass:[self class]] pathForResource:@"IOSUnityBundle" ofType:@"bundle"]]; if (orangeImage == nil){ orangeImage = [[UIImage imageWithContentsOfFile:[refreshBundle pathForResource:imageName ofType:@"png"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; } }else{ orangeImage = [UIImage imageNamed:imageName]; } return orangeImage; } // -(void)closeAction{ [self close]; } // -(void)searchAction{ self.animationView.hidden = NO; self.shoseimage.hidden = NO; if(self.searchDeviceTask){ self.searchDeviceTask(); } } -(NSMutableArray*)deviceArray{ if (!_deviceArray){ _deviceArray = [NSMutableArray new]; } return _deviceArray; } #pragma mark --------------------------------------------------- UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ // NSLog(@"数据源个数 = %ld",self.deviceArray.count); return self.deviceArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *identifier = @"deviceId"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier]; } CBPeripheral * peripheral = self.deviceArray[indexPath.row]; // NSString *string = [self.deviceArray objectAtIndex:indexPath.row]; cell.textLabel.text = peripheral.name; cell.detailTextLabel.text = peripheral.identifier.UUIDString; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.selectionStyle = NO; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ // [tableView deselectRowAtIndexPath:indexPath animated:YES]; CBPeripheral * peripheral = self.deviceArray[indexPath.row]; NSLog(@"self.deviceArray.index == %@",peripheral); if (self.connectDeviceBlock!=nil){ self.connectDeviceBlock(peripheral); } [self close]; [self close]; } //-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ // return 44; //} // //-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ // // UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44)]; // titleLabel.backgroundColor = BackGroundColor; // titleLabel.text = MyLocalizedString(@"Available Device"); // titleLabel.textColor = NormalTextColor; // titleLabel.textAlignment = NSTextAlignmentCenter; // return titleLabel; // //} //- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ // [self close]; //} - (void)close{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [UIView animateWithDuration:0.25 animations:^{ self.view.alpha = 0; [self.view removeFromSuperview]; }completion:^(BOOL finished) { [self.view removeFromSuperview]; }]; }); } - (void)startAnimation{ [UIView animateWithDuration:1 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{ self.animationView.transform = CGAffineTransformRotate(self.animationView.transform,(M_PI/2.0)); }completion:^(BOOL finished){ [self startAnimation]; }]; } -(void)hideAnimation{ self.animationView.hidden = YES; self.shoseimage.hidden = YES; } @end