Pārlūkot izejas kodu

1.扫码页面UI以及提示语修复

huangxiaodong 2 gadi atpakaļ
vecāks
revīzija
e04e4cfcd9

+ 21 - 0
创维盒子/双子星云手机/Assets.xcassets/Guide/qrCode_scan_bg.imageset/Contents.json

@@ -0,0 +1,21 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "filename" : "qrCode_scan_bg@2x.png",
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

BIN
创维盒子/双子星云手机/Assets.xcassets/Guide/qrCode_scan_bg.imageset/qrCode_scan_bg@2x.png


+ 21 - 0
创维盒子/双子星云手机/Assets.xcassets/Guide/qrCode_scan_line.imageset/Contents.json

@@ -0,0 +1,21 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "filename" : "qrCode_scan_line@2x.png",
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

BIN
创维盒子/双子星云手机/Assets.xcassets/Guide/qrCode_scan_line.imageset/qrCode_scan_line@2x.png


+ 63 - 7
创维盒子/双子星云手机/Class/Guide/QRCodeScanViewController.m

@@ -21,7 +21,9 @@
 
 //辅助区域框
 
-@property(nonatomic,strong)UIView * cyanView;
+@property(nonatomic,strong)UIImageView * cyanEdgeImageView;
+@property(nonatomic,strong)UIImageView * qrCodeScanLine;
+@property(nonatomic,strong)NSTimer * scanLineTimer;
 
 ////打开灯光btn,默认为hidden
 //
@@ -58,6 +60,12 @@
     }
 }
 
+-(void)viewWillDisappear:(BOOL)animated
+{
+    [super viewWillDisappear:animated];
+    [_scanLineTimer  invalidate];
+}
+
 //开始扫描二维码
 
 -(void)startScan{
@@ -124,14 +132,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;
 
-    cyanView.layer.borderColor =[UIColor cyanColor].CGColor;
+    _cyanEdgeImageView.image = [UIImage imageNamed:@"qrCode_scan_bg"];
+    [self.view addSubview:_cyanEdgeImageView];
 
-    [self.view addSubview:cyanView];
+    _qrCodeScanLine=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width-200, 1)];
 
+    _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 = @"请扫描序列号二维码";
+    tipLib.font = [UIFont systemFontOfSize:14.0];
+    tipLib.textAlignment = NSTextAlignmentCenter;
+    tipLib.textColor = [UIColor whiteColor];
+    [self.view addSubview:tipLib];
+    
     //6.创建检测光感源
 
     AVCaptureVideoDataOutput *guangOutPut = [[AVCaptureVideoDataOutput alloc] init];
@@ -162,6 +185,30 @@ AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device
     [self.session startRunning];
 }
 
+#pragma mark timer 处理线上下移动
+bool isDownType = YES;
+-(void)scanLineDownAndUpFun
+{
+    [UIView animateWithDuration:0.01 animations:^{
+        
+        if(isDownType && self->_qrCodeScanLine.hw_y <= self->_cyanEdgeImageView.hw_h){
+            self->_qrCodeScanLine.hw_y += 2;
+            
+            if(self->_cyanEdgeImageView.hw_h - self->_qrCodeScanLine.hw_y <= 5){
+                isDownType = NO;
+            }
+        }
+        else if(!isDownType && self->_qrCodeScanLine.hw_y >= 0)
+        {
+            self->_qrCodeScanLine.hw_y -= 2;
+            
+            if(self->_qrCodeScanLine.hw_y <= 5){
+                isDownType = YES;
+            }
+        }
+    }];
+}
+
 //实现扫描的回调代理方法
 
 - (void)captureOutput:(AVCaptureOutput*)captureOutput didOutputMetadataObjects:(NSArray*)metadataObjects fromConnection:(AVCaptureConnection*)connection{
@@ -177,16 +224,24 @@ AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device
         /*扫描到有用信息时取消扫描*/
         NSString *resStr = object.stringValue;//RK3908P1V62112465
         
-        if(resStr.length == @"Ch0IKJCY9lOgokjfPBFE1cowdC1+tj7ywB2pZgSzjhc=".length)
+        if(resStr.length > 22)
         {
-            resStr = [RSATool AES128Decrypt:resStr key:@"fvO8gAfNSr1tbdQe"];
+            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:@"扫码成功!正在为你快速连接中"] show];
+            [_scanLineTimer  invalidate];
+            
             NSDictionary *newDict = [[NSDictionary alloc] initWithObjectsAndKeys:resStr,Const_Have_Add_Device_SN, nil];
             [HWDataManager setObjectWithKey:Const_Have_Add_Device value:newDict];
             
@@ -200,6 +255,7 @@ AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device
         }
     }else{
         
+        [[iToast makeText:@"小主,二维码错误,请扫描正确的序列号哦"] show];
         NSLog(@"没有扫描到数据");
         
     }