Просмотр исходного кода

1.修改iOS扫码返回,改为外部主动调用。

Pen Li 7 лет назад
Родитель
Сommit
957adc0abb

+ 6 - 0
common/Camera/RACameraViewController.m

@@ -84,6 +84,9 @@
                     
                     NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
                     NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
+                    if (!appName) {
+                        appName = [infoDict objectForKey:@"CFBundleName"];
+                    }
                     __weak typeof(self) weakSelf = self;
                     UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Camera access denied, please change %@ setting, allow App use camera. (setting -> privacy -> camera enable %@)",[UIDevice currentDevice].model,appName] preferredStyle:UIAlertControllerStyleAlert];
                     UIAlertAction *action = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
@@ -179,6 +182,9 @@
         
         NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
         NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
+        if (!appName) {
+            appName = [infoDict objectForKey:@"CFBundleName"];
+        }
         __weak typeof(self) weakSelf = self;
         UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Camera access denied, please change %@ setting, allow App use camera. (setting -> privacy -> camera enable %@)",[UIDevice currentDevice].model,appName] preferredStyle:UIAlertControllerStyleAlert];
         UIAlertAction *action = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

+ 15 - 3
common/QRCode/QRCode.storyboard

@@ -1,12 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
     <device id="retina5_5" orientation="landscape">
         <adaptation id="fullscreen"/>
     </device>
     <dependencies>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
-        <capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
         <capability name="Safe area layout guides" minToolsVersion="9.0"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
@@ -58,6 +57,13 @@
                                     <action selector="scannerBtnTouchUpOutSide:" destination="41J-NQ-wiU" eventType="touchUpOutside" id="O42-nG-qkE"/>
                                 </connections>
                             </button>
+                            <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="5fS-uQ-uh4">
+                                <rect key="frame" x="10" y="20" width="30" height="30"/>
+                                <state key="normal" image="qr_back_btn"/>
+                                <connections>
+                                    <action selector="backBtnClick:" destination="41J-NQ-wiU" eventType="touchUpInside" id="ifJ-hi-DTG"/>
+                                </connections>
+                            </button>
                         </subviews>
                         <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                         <constraints>
@@ -70,6 +76,7 @@
                             <constraint firstItem="vCI-Zm-N7X" firstAttribute="centerX" secondItem="aiT-qZ-M5f" secondAttribute="centerX" id="8dy-2H-2iw"/>
                             <constraint firstItem="D8z-rA-Qpf" firstAttribute="width" secondItem="aiT-qZ-M5f" secondAttribute="width" id="BuV-2a-gda"/>
                             <constraint firstItem="0ig-dn-iSa" firstAttribute="centerY" secondItem="vCI-Zm-N7X" secondAttribute="centerY" id="DcB-0a-gGt"/>
+                            <constraint firstItem="5fS-uQ-uh4" firstAttribute="leading" secondItem="TEW-wV-M4S" secondAttribute="leading" constant="10" id="FST-Qu-NEj"/>
                             <constraint firstItem="4DJ-GK-9l9" firstAttribute="leading" secondItem="D8z-rA-Qpf" secondAttribute="leading" id="OtU-1g-dHc"/>
                             <constraint firstItem="0ig-dn-iSa" firstAttribute="centerY" secondItem="vCI-Zm-N7X" secondAttribute="centerY" id="R8a-93-kVx"/>
                             <constraint firstItem="D8z-rA-Qpf" firstAttribute="leading" secondItem="aiT-qZ-M5f" secondAttribute="leading" id="RYY-iZ-sc1"/>
@@ -79,6 +86,7 @@
                             <constraint firstItem="vCI-Zm-N7X" firstAttribute="centerX" secondItem="aiT-qZ-M5f" secondAttribute="centerX" constant="-80" id="Z6F-qY-EEv"/>
                             <constraint firstAttribute="trailing" secondItem="vCI-Zm-N7X" secondAttribute="trailing" constant="70" id="cSr-ne-Xxd"/>
                             <constraint firstItem="vCI-Zm-N7X" firstAttribute="centerY" secondItem="aiT-qZ-M5f" secondAttribute="centerY" constant="-110" id="e2p-ZK-jAC"/>
+                            <constraint firstItem="5fS-uQ-uh4" firstAttribute="top" secondItem="TEW-wV-M4S" secondAttribute="top" constant="20" id="e46-jb-ZUK"/>
                             <constraint firstAttribute="trailing" secondItem="0ig-dn-iSa" secondAttribute="trailing" constant="80" id="eCS-j2-u7d"/>
                             <constraint firstAttribute="bottom" secondItem="0ig-dn-iSa" secondAttribute="bottom" constant="100" id="exY-By-XcQ"/>
                             <constraint firstItem="vCI-Zm-N7X" firstAttribute="centerY" secondItem="aiT-qZ-M5f" secondAttribute="centerY" constant="-70" id="fNO-9Q-eMD"/>
@@ -159,6 +167,7 @@
                         </variation>
                     </view>
                     <connections>
+                        <outlet property="backBtn" destination="5fS-uQ-uh4" id="VhC-Xf-GM8"/>
                         <outlet property="maskView" destination="4DJ-GK-9l9" id="naM-uL-H99"/>
                         <outlet property="previewContainer" destination="D8z-rA-Qpf" id="XCg-1T-zSa"/>
                         <outlet property="scanBtn" destination="0ig-dn-iSa" id="JUa-KJ-cvr"/>
@@ -170,4 +179,7 @@
             <point key="canvasLocation" x="-155.70652173913044" y="160.86956521739131"/>
         </scene>
     </scenes>
+    <resources>
+        <image name="qr_back_btn" width="30" height="30"/>
+    </resources>
 </document>

+ 2 - 1
common/QRCode/RAQRCodeScannerViewController.h

@@ -10,7 +10,8 @@
 
 @interface RAQRCodeScannerViewController : UIViewController
 
-@property (nonatomic,copy) void (^completion)(NSString *value);
+@property (nonatomic,copy) void (^QRCodeViewControllerDidCompletion)(RAQRCodeScannerViewController *qrcodeViewController, NSString *value);///< 需要在Block中返回
+@property (nonatomic,copy) void (^QRCodeViewControllerDidCanceled)(RAQRCodeScannerViewController *qrcodeViewController);///< 需要在Block中返回
 
 + (instancetype)viewControllerFromStoryboard;
 

+ 35 - 5
common/QRCode/RAQRCodeScannerViewController.m

@@ -15,6 +15,7 @@
 @property (nonatomic,strong) IBOutlet UIView *previewContainer;
 @property (strong, nonatomic) IBOutlet UIView *maskView;
 @property (strong, nonatomic) IBOutlet UIButton *scanBtn;
+@property (strong, nonatomic) IBOutlet UIButton *backBtn;
 
 @property (nonatomic,strong) AVCaptureDevice *device;
 @property (nonatomic,strong) AVCaptureDeviceInput *input;
@@ -29,6 +30,8 @@
 @property (nonatomic,strong) CAShapeLayer *maskLayer;
 @property (nonatomic,strong) CAShapeLayer *rectLayer;
 
+@property (nonatomic,assign) BOOL navigationBarStatus;
+
 @end
 
 @implementation RAQRCodeScannerViewController
@@ -45,6 +48,10 @@
 - (void)viewDidLoad {
     [super viewDidLoad];
     // Do any additional setup after loading the view.
+    if (self.navigationController) {
+        self.navigationBarStatus = self.navigationController.navigationBarHidden;
+        [self.navigationController setNavigationBarHidden:YES animated:NO];
+    }
     
     self.scanerView.layer.borderColor = [UIColor blackColor].CGColor;
     self.scanerView.layer.borderWidth = 0.5f;
@@ -77,10 +84,13 @@
                     
                     NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
                     NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
+                    if (!appName) {
+                        appName = [infoDict objectForKey:@"CFBundleName"];
+                    }
                     __weak typeof(self) weakSelf = self;
                     UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Camera access denied, please change %@ setting, allow App use camera. (setting -> privacy -> camera enable %@)",[UIDevice currentDevice].model,appName] preferredStyle:UIAlertControllerStyleAlert];
                     UIAlertAction *action = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-                        [weakSelf dismissViewControllerAnimated:YES completion:nil];
+                        [weakSelf didCancel];
                     }];
                     [alert addAction:action];
                     [self presentViewController:alert animated:YES completion:nil];
@@ -236,6 +246,17 @@
     return _scanLineLayer;
 }
 
+#pragma mark - Private
+
+- (void)didCancel {
+    if (self.QRCodeViewControllerDidCanceled) {
+        self.QRCodeViewControllerDidCanceled(self);
+        if (self.navigationController) {
+            [self.navigationController setNavigationBarHidden:self.navigationBarStatus animated:NO];
+        }
+    }
+}
+
 #pragma mark - Init
 
 - (void)initCapture {
@@ -246,10 +267,13 @@
         
         NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
         NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
+        if (!appName) {
+            appName = [infoDict objectForKey:@"CFBundleName"];
+        }
         __weak typeof(self) weakSelf = self;
         UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Camera access denied, please change %@ setting, allow App use camera. (setting -> privacy -> camera enable %@)",[UIDevice currentDevice].model,appName] preferredStyle:UIAlertControllerStyleAlert];
         UIAlertAction *action = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-            [weakSelf dismissViewControllerAnimated:YES completion:nil];
+            [weakSelf didCancel];
         }];
         [alert addAction:action];
         [self presentViewController:alert animated:YES completion:nil];
@@ -326,10 +350,12 @@
         
         AVMetadataMachineReadableCodeObject *metadataObject = [metadataObjects objectAtIndex:0];
         NSString *codeValue = metadataObject.stringValue;
-        if (self.completion) {
-            self.completion(codeValue);
+        if (self.QRCodeViewControllerDidCompletion) {
+            self.QRCodeViewControllerDidCompletion(self, codeValue);
+            if (self.navigationController) {
+                [self.navigationController setNavigationBarHidden:self.navigationBarStatus animated:NO];
+            }
         }
-        [self.navigationController popViewControllerAnimated:YES];
     }
     
 }
@@ -352,6 +378,10 @@
     self.scannerEnable = NO;
 }
 
+- (IBAction)backBtnClick:(UIButton *)sender {
+    [self didCancel];
+}
+
 #pragma mark - Utils
 
 + (UIImage *)imageWithColor:(UIColor *)color Size:(CGSize)size {

+ 6 - 0
common/QRCode/qrcode.xcassets/Contents.json

@@ -0,0 +1,6 @@
+{
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

+ 23 - 0
common/QRCode/qrcode.xcassets/qr_back_btn.imageset/Contents.json

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

BIN
common/QRCode/qrcode.xcassets/qr_back_btn.imageset/qr_back_btn.png


BIN
common/QRCode/qrcode.xcassets/qr_back_btn.imageset/qr_back_btn@2x.png


BIN
common/QRCode/qrcode.xcassets/qr_back_btn.imageset/qr_back_btn@3x.png