123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- //
- // 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 ()<UITableViewDelegate,UITableViewDataSource>
- @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<UITouch *> *)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
|