// // PBScanningViewController.m // IphoneBIMe // // Created by zjf on 2020/7/27. // Copyright © 2020 ProBIM. All rights reserved. // #import "PBScanningViewController.h" //#import "SGQRCode.h" @interface PBScanningViewController () //{ // SGQRCodeObtain *obtain; //} //@property (nonatomic, strong) SGQRCodeScanView *scanView; //@property (nonatomic, strong) UIButton *flashlightBtn; //@property (nonatomic, strong) UILabel *promptLabel; //@property (nonatomic, assign) BOOL isSelectedFlashlightBtn; //@property (nonatomic, strong) UIView *bottomView; @end @implementation PBScanningViewController - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; /// 二维码开启方法 // [obtain startRunningWithBefore:nil completion:nil]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; // [self.scanView addTimer]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; // [self.scanView removeTimer]; // [self removeFlashlightBtn]; // [obtain stopRunning]; } //- (void)dealloc { // NSLog(@"WCQRCodeVC - dealloc"); // [self removeScanningView]; //} - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. // self.view.backgroundColor = [UIColor blackColor]; // obtain = [SGQRCodeObtain QRCodeObtain]; // // [self setupQRCodeScan]; // [self setupNavigationBar]; // [self.view addSubview:self.scanView]; // [self.view addSubview:self.promptLabel]; // /// 为了 UI 效果 // [self.view addSubview:self.bottomView]; } //- (void)setupQRCodeScan { // __weak typeof(self) weakSelf = self; // // SGQRCodeObtainConfigure *configure = [SGQRCodeObtainConfigure QRCodeObtainConfigure]; // configure.sampleBufferDelegate = YES; // [obtain establishQRCodeObtainScanWithController:self configure:configure]; // [obtain setBlockWithQRCodeObtainScanResult:^(SGQRCodeObtain *obtain, NSString *result) { // if (result) { // [YJProgressHUD showMessage:result inView:weakSelf.view]; // [MBProgressHUD SG_showMBProgressHUDWithModifyStyleMessage:@"正在处理..." toView:weakSelf.view]; // [obtain stopRunning]; // [obtain playSoundName:@"SGQRCode.bundle/sound.caf"]; // ScanSuccessJumpVC *jumpVC = [[ScanSuccessJumpVC alloc] init]; // jumpVC.comeFromVC = ScanSuccessJumpComeFromWC; // jumpVC.jump_URL = result; // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // [MBProgressHUD SG_hideHUDForView:weakSelf.view]; // [weakSelf.navigationController pushViewController:jumpVC animated:YES]; // }); // } // }]; // [obtain setBlockWithQRCodeObtainScanBrightness:^(SGQRCodeObtain *obtain, CGFloat brightness) { // if (brightness < - 1) { // [weakSelf.view addSubview:weakSelf.flashlightBtn]; // } else { // if (weakSelf.isSelectedFlashlightBtn == NO) { // [weakSelf removeFlashlightBtn]; // } // } // }]; //} //- (void)setupNavigationBar { // self.navigationItem.title = @"扫一扫"; //// self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"相册" style:(UIBarButtonItemStyleDone) target:self action:@selector(rightBarButtonItenAction)]; //} //- (void)rightBarButtonItenAction { // __weak typeof(self) weakSelf = self; // // [obtain establishAuthorizationQRCodeObtainAlbumWithController:nil]; // if (obtain.isPHAuthorization == YES) { // [self.scanView removeTimer]; // } // [obtain setBlockWithQRCodeObtainAlbumDidCancelImagePickerController:^(SGQRCodeObtain *obtain) { // [weakSelf.view addSubview:weakSelf.scanView]; // }]; // [obtain setBlockWithQRCodeObtainAlbumResult:^(SGQRCodeObtain *obtain, NSString *result) { // [MBProgressHUD SG_showMBProgressHUDWithModifyStyleMessage:@"正在处理..." toView:weakSelf.view]; // if (result == nil) { // NSLog(@"暂未识别出二维码"); // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // [MBProgressHUD SG_hideHUDForView:weakSelf.view]; // [MBProgressHUD SG_showMBProgressHUDWithOnlyMessage:@"未发现二维码/条形码" delayTime:1.0]; // }); // } else { // ScanSuccessJumpVC *jumpVC = [[ScanSuccessJumpVC alloc] init]; // jumpVC.comeFromVC = ScanSuccessJumpComeFromWC; // if ([result hasPrefix:@"http"]) { // jumpVC.jump_URL = result; // } else { // jumpVC.jump_bar_code = result; // } // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // [MBProgressHUD SG_hideHUDForView:weakSelf.view]; // [weakSelf.navigationController pushViewController:jumpVC animated:YES]; // }); // } // }]; //} //- (SGQRCodeScanView *)scanView { // if (!_scanView) { // _scanView = [[SGQRCodeScanView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0.9 * self.view.frame.size.height)]; // } // return _scanView; //} //- (void)removeScanningView { // [self.scanView removeTimer]; // [self.scanView removeFromSuperview]; // self.scanView = nil; //} // //- (UILabel *)promptLabel { // if (!_promptLabel) { // _promptLabel = [[UILabel alloc] init]; // _promptLabel.backgroundColor = [UIColor clearColor]; // CGFloat promptLabelX = 0; // CGFloat promptLabelY = 0.73 * self.view.frame.size.height; // CGFloat promptLabelW = self.view.frame.size.width; // CGFloat promptLabelH = 25; // _promptLabel.frame = CGRectMake(promptLabelX, promptLabelY, promptLabelW, promptLabelH); // _promptLabel.textAlignment = NSTextAlignmentCenter; // _promptLabel.font = [UIFont boldSystemFontOfSize:13.0]; // _promptLabel.textColor = [[UIColor whiteColor] colorWithAlphaComponent:0.6]; // _promptLabel.text = @"将二维码/条码放入框内, 即可自动扫描"; // } // return _promptLabel; //} // //- (UIView *)bottomView { // if (!_bottomView) { // _bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.scanView.frame), self.view.frame.size.width, self.view.frame.size.height - CGRectGetMaxY(self.scanView.frame))]; // _bottomView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5]; // } // return _bottomView; //} // //#pragma mark - - - 闪光灯按钮 //- (UIButton *)flashlightBtn { // if (!_flashlightBtn) { // // 添加闪光灯按钮 // _flashlightBtn = [UIButton buttonWithType:(UIButtonTypeCustom)]; // CGFloat flashlightBtnW = 30; // CGFloat flashlightBtnH = 30; // CGFloat flashlightBtnX = 0.5 * (self.view.frame.size.width - flashlightBtnW); // CGFloat flashlightBtnY = 0.55 * self.view.frame.size.height; // _flashlightBtn.frame = CGRectMake(flashlightBtnX, flashlightBtnY, flashlightBtnW, flashlightBtnH); // [_flashlightBtn setBackgroundImage:[UIImage imageNamed:@"SGQRCodeFlashlightOpenImage"] forState:(UIControlStateNormal)]; // [_flashlightBtn setBackgroundImage:[UIImage imageNamed:@"SGQRCodeFlashlightCloseImage"] forState:(UIControlStateSelected)]; // [_flashlightBtn addTarget:self action:@selector(flashlightBtn_action:) forControlEvents:UIControlEventTouchUpInside]; // } // return _flashlightBtn; //} // //- (void)flashlightBtn_action:(UIButton *)button { // if (button.selected == NO) { // [obtain openFlashlight]; // self.isSelectedFlashlightBtn = YES; // button.selected = YES; // } else { // [self removeFlashlightBtn]; // } //} // //- (void)removeFlashlightBtn { // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // [obtain closeFlashlight]; // self.isSelectedFlashlightBtn = NO; // self.flashlightBtn.selected = NO; // [self.flashlightBtn removeFromSuperview]; // }); //} /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end