Quellcode durchsuchen

1.更换设备扫码同步扫码设备的UI和逻辑

huangxiaodong vor 1 Jahr
Ursprung
Commit
0f610ddbab

+ 73 - 7
创维盒子/双子星云手机/Class/Set/ChangeDevice/QRCodeScanForChangeDeviceViewController.m

@@ -9,7 +9,7 @@
 #import <AVFoundation/AVFoundation.h>
 #import <ImageIO/ImageIO.h>
 #import "MySetViewController.h"
-
+#import "RSATool.h"
 @interface QRCodeScanForChangeDeviceViewController ()<AVCaptureMetadataOutputObjectsDelegate,AVCaptureVideoDataOutputSampleBufferDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>
 
 @property(nonatomic,strong)AVCaptureVideoPreviewLayer *layer;
@@ -20,7 +20,9 @@
 
 //辅助区域框
 
-@property(nonatomic,strong)UIView * cyanView;
+@property(nonatomic,strong)UIImageView * cyanEdgeImageView;
+@property(nonatomic,strong)UIImageView * qrCodeScanLine;
+@property(nonatomic,strong)NSTimer * scanLineTimer;
 
 ////打开灯光btn,默认为hidden
 //
@@ -57,6 +59,12 @@
     }
 }
 
+-(void)viewWillDisappear:(BOOL)animated
+{
+    [super viewWillDisappear:animated];
+    [_scanLineTimer  invalidate];
+}
+
 //开始扫描二维码
 
 -(void)startScan{
@@ -123,14 +131,29 @@ AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device
 
     //5.创建view,通过layer层进行设置边框宽度和颜色,用来辅助展示扫描的区域
 
-    UIView * cyanView=[[UIView alloc] initWithFrame:CGRectMake(100, 250, self.view.frame.size.width-200, self.view.frame.size.width-200)];
+    _cyanEdgeImageView=[[UIImageView alloc] initWithFrame:CGRectMake(100, 250, self.view.frame.size.width-200, self.view.frame.size.width-200)];
 
-    cyanView.layer.borderWidth=2;
+//    _cyanEdgeImageView.layer.borderWidth=2;
+//
+//    _cyanEdgeImageView.layer.borderColor =[UIColor cyanColor].CGColor;
+
+    _cyanEdgeImageView.image = [UIImage imageNamed:@"qrCode_scan_bg"];
+    [self.view addSubview:_cyanEdgeImageView];
 
-    cyanView.layer.borderColor =[UIColor cyanColor].CGColor;
+    _qrCodeScanLine=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width-200, 1)];
 
-    [self.view addSubview:cyanView];
+    _qrCodeScanLine.image = [UIImage imageNamed:@"qrCode_scan_line"];
+    [_cyanEdgeImageView addSubview:_qrCodeScanLine];
 
+    _scanLineTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(scanLineDownAndUpFun) userInfo:nil repeats:YES];
+    
+    UILabel *tipLib = [[UILabel alloc] initWithFrame:CGRectMake(_cyanEdgeImageView.hw_x, _cyanEdgeImageView.hw_max_y + 15, _cyanEdgeImageView.hw_w, 20)];
+    tipLib.text = NSLocalizedString(@"guide_qrcoede_tips_please",nil);
+    tipLib.font = [UIFont systemFontOfSize:14.0];
+    tipLib.textAlignment = NSTextAlignmentCenter;
+    tipLib.textColor = [UIColor whiteColor];
+    [self.view addSubview:tipLib];
+    
     //6.创建检测光感源
 
     AVCaptureVideoDataOutput *guangOutPut = [[AVCaptureVideoDataOutput alloc] init];
@@ -161,6 +184,31 @@ AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device
     [self.session startRunning];
 }
 
+#pragma mark timer 处理线上下移动
+bool isDownType22 = YES;
+-(void)scanLineDownAndUpFun
+{
+    [UIView animateWithDuration:0.01 animations:^{
+        
+        if(isDownType22 && self->_qrCodeScanLine.hw_y <= self->_cyanEdgeImageView.hw_h){
+            self->_qrCodeScanLine.hw_y += 2;
+            
+            if(self->_cyanEdgeImageView.hw_h - self->_qrCodeScanLine.hw_y <= 5){
+                isDownType22 = NO;
+            }
+        }
+        else if(!isDownType22 && self->_qrCodeScanLine.hw_y >= 0)
+        {
+            self->_qrCodeScanLine.hw_y -= 2;
+            
+            if(self->_qrCodeScanLine.hw_y <= 5){
+                isDownType22 = YES;
+            }
+        }
+    }];
+}
+
+
 //实现扫描的回调代理方法
 
 - (void)captureOutput:(AVCaptureOutput*)captureOutput didOutputMetadataObjects:(NSArray*)metadataObjects fromConnection:(AVCaptureConnection*)connection{
@@ -175,7 +223,24 @@ AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device
         
         /*扫描到有用信息时取消扫描*/
         NSString *resStr = object.stringValue;//RK3908P1V62112465
-        if ([resStr containsString:@"RK"] && (resStr.length == @"RK3908P1V62112465".length)){
+        if(resStr.length > 22)
+        {
+            NSString*desStr  = [RSATool AES128Decrypt:resStr key:@"fvO8gAfNSr1tbdQe"];
+            
+            if(desStr){//能解码
+                resStr = desStr;
+            }
+        }
+        //Ch0IKJCY9lOgokjfPBFE1cowdC1+tj7ywB2pZgSzjhc=
+        //sgl5OzDoVjY5SmGuL50/EnQ4n6Kw+DzRiE1oUjq7yAM=
+        
+        if (([resStr containsString:@"RK"] && (resStr.length == @"RK3908P1V62112465".length))
+            || resStr.length == @"0333933700223250017273".length
+             ){
+            
+            [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_ok",nil)] show];
+            [_scanLineTimer  invalidate];
+            
             NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
             NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithDictionary:deviceDict];
             [dict setObject:resStr forKey:Const_Have_Add_Device_SN];
@@ -195,6 +260,7 @@ AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device
             }
         }
     }else{
+        [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_error",nil)] show];
         NSLog(@"没有扫描到数据");
     }
 }