Browse Source

1.修改视图使之适配iPhone。
2.增加Cancel按钮。

Pen Li 9 years ago
parent
commit
f0534a6fa6
2 changed files with 46 additions and 22 deletions
  1. 39 15
      common/ScannerViewController.m
  2. 7 7
      common/cam_scan.storyboard

+ 39 - 15
common/ScannerViewController.m

@@ -184,11 +184,19 @@
     
     self.navigationItem.leftBarButtonItem = closeButton;
     
+
+}
+
+- (void)viewDidAppear:(BOOL)animated {
+    [super viewDidAppear:animated];
+    
+    // 只有在此方法中取得的self.focusZone.frame才正确。
     //        return;
-    [self.backgroundView removeFromSuperview];
+    //    [self.backgroundView removeFromSuperview];
     //self.back = (ScannerControllerView*)self.view;
     self.backgroundView.highLightRect = CGRectInset(self.focusZone.frame,6,6);
-   // self.backgroundView.autoresizingMask=0xff;
+    [self.backgroundView setNeedsDisplay];
+    // self.backgroundView.autoresizingMask=0xff;
     self.handelOutput = false;
     
     
@@ -249,20 +257,20 @@
     _previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
     _previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
     
-//    _previewLayer.orientation= AVCaptureVideoOrientationLandscapeRight;
+    //    _previewLayer.orientation= AVCaptureVideoOrientationLandscapeRight;
     UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
     switch (orientation) {
             
-//            UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,
-//            UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
-//            UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,
-//            UIInterfaceOrientationLandscapeRight
+            //            UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,
+            //            UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
+            //            UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,
+            //            UIInterfaceOrientationLandscapeRight
             
             
-//            AVCaptureVideoOrientationPortrait           = 1,
-//            AVCaptureVideoOrientationPortraitUpsideDown = 2,
-//            AVCaptureVideoOrientationLandscapeRight     = 3,
-//            AVCaptureVideoOrientationLandscapeLeft      = 4,
+            //            AVCaptureVideoOrientationPortrait           = 1,
+            //            AVCaptureVideoOrientationPortraitUpsideDown = 2,
+            //            AVCaptureVideoOrientationLandscapeRight     = 3,
+            //            AVCaptureVideoOrientationLandscapeLeft      = 4,
         case UIInterfaceOrientationPortrait:
             _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationPortrait;
             break;
@@ -285,11 +293,12 @@
     
     _previewLayer.bounds = rect;
     _previewLayer.position = CGPointMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds));
-    [self.view.layer addSublayer:_previewLayer];
-    
+    //    [self.view.layer addSublayer:_previewLayer];
+    [self.view.layer insertSublayer:_previewLayer atIndex:0];
     
     
-    [self.view addSubview:self.backgroundView];
+    //    [self.view addSubview:self.backgroundView];
+    [self.view bringSubviewToFront:self.backgroundView];
     
     //    [self.view addSubview:self.ScannerControl.view];
     //    CGRect rt = self.ScannerControl.scannerZone.bounds;
@@ -309,7 +318,7 @@
     _boundingBox = [[SCShapeView alloc] initWithFrame:self.view.bounds];
     _boundingBox.backgroundColor = [UIColor clearColor];
     _boundingBox.hidden = YES;
-    [self.view addSubview:_boundingBox];
+    [self.view insertSubview:_boundingBox belowSubview:self.backgroundView];
     
     // Add a label to display the resultant message
     _decodedMessage = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(self.view.bounds) - 75, CGRectGetWidth(self.view.bounds), 75)];
@@ -318,6 +327,15 @@
     _decodedMessage.textColor = [UIColor darkGrayColor];
     _decodedMessage.textAlignment = NSTextAlignmentCenter;
     [self.view addSubview:_decodedMessage];
+
+    _decodedMessage.userInteractionEnabled = YES;
+    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
+    [backBtn setTitle:@"cancel" forState:UIControlStateNormal];
+    backBtn.titleLabel.backgroundColor = [UIColor whiteColor];
+    [backBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
+    backBtn.frame = CGRectMake(CGRectGetMaxX(_decodedMessage.frame) - 70, 0, 60, CGRectGetHeight(_decodedMessage.frame));
+    [_decodedMessage addSubview:backBtn];
+    [backBtn addTarget:self action:@selector(backButtonClick:) forControlEvents:UIControlEventTouchUpInside];
     
     self.scanButton.layer.shadowColor = [UIColor blackColor].CGColor;
     self.scanButton.layer.shadowOffset = CGSizeMake(0, 0);
@@ -327,7 +345,13 @@
     self.scanButton.layer.borderWidth = 15;
     // Start the AVSession running
     [session startRunning];
+    
 }
+
+- (void)backButtonClick:(UIButton *)sender {
+    [self dismissViewControllerAnimated:YES completion:nil];
+}
+
 //#pragma mark - ScannerControllerDelegate
 //-(void)BeginScan:(bool)begin
 //{

+ 7 - 7
common/cam_scan.storyboard

@@ -81,18 +81,18 @@
                                 <subviews>
                                     <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="pick_bg" translatesAutoresizingMaskIntoConstraints="NO" id="AWN-OI-m1R">
                                         <rect key="frame" x="284" y="412" width="200" height="200"/>
-                                        <color key="backgroundColor" red="0.064155410240000002" green="1" blue="0.59383154270000005" alpha="1" colorSpace="calibratedRGB"/>
+                                        <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
                                         <constraints>
                                             <constraint firstAttribute="height" constant="200" id="38l-YS-3Mf"/>
                                             <constraint firstAttribute="width" constant="200" id="J44-fN-4A7"/>
                                         </constraints>
                                     </imageView>
                                     <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="wordWrap" translatesAutoresizingMaskIntoConstraints="NO" id="V66-PS-hiP" userLabel="Button scan">
-                                        <rect key="frame" x="668" y="924" width="80" height="80"/>
+                                        <rect key="frame" x="648" y="824" width="100" height="100"/>
                                         <color key="backgroundColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                                         <constraints>
-                                            <constraint firstAttribute="width" constant="80" id="NqQ-6g-9PW"/>
-                                            <constraint firstAttribute="height" constant="80" id="bJd-iL-CJN"/>
+                                            <constraint firstAttribute="width" constant="100" id="NqQ-6g-9PW"/>
+                                            <constraint firstAttribute="height" constant="100" id="bJd-iL-CJN"/>
                                         </constraints>
                                         <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                         <state key="normal">
@@ -105,16 +105,16 @@
                                             </userDefinedRuntimeAttribute>
                                         </userDefinedRuntimeAttributes>
                                         <connections>
-                                            <action selector="ScanButtonClick:" destination="kVd-Bz-inR" eventType="touchUpInside" id="pnM-dE-N0i"/>
+                                            <action selector="ScanButtonClick:" destination="tcU-ug-x8T" eventType="touchUpInside" id="lva-af-UxF"/>
                                         </connections>
                                     </button>
                                 </subviews>
-                                <color key="backgroundColor" red="0.25435081980000002" green="0.75957768849999996" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                                <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
                                 <constraints>
                                     <constraint firstAttribute="trailing" secondItem="V66-PS-hiP" secondAttribute="trailing" constant="20" id="aGy-Ut-mhz"/>
                                     <constraint firstItem="AWN-OI-m1R" firstAttribute="centerX" secondItem="ym0-7Q-YSA" secondAttribute="centerX" id="dnB-Xj-nye"/>
                                     <constraint firstItem="AWN-OI-m1R" firstAttribute="centerY" secondItem="ym0-7Q-YSA" secondAttribute="centerY" id="ijX-CV-tZ4"/>
-                                    <constraint firstAttribute="bottom" secondItem="V66-PS-hiP" secondAttribute="bottom" constant="20" id="rm6-2h-eOb"/>
+                                    <constraint firstAttribute="bottom" secondItem="V66-PS-hiP" secondAttribute="bottom" constant="100" id="rm6-2h-eOb"/>
                                 </constraints>
                             </view>
                         </subviews>