zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
//
//  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