@@ -150,6 +150,17 @@ extension CodeScannerView {
150
150
return button
151
151
} ( )
152
152
153
+ private lazy var manualSelectButton : UIButton = {
154
+ let button = UIButton ( type: . system)
155
+ let image = UIImage ( systemName: " photo.on.rectangle " )
156
+ let background = UIImage ( systemName: " capsule.fill " ) ? . withTintColor ( . systemBackground, renderingMode: . alwaysOriginal)
157
+ button. setImage ( image, for: . normal)
158
+ button. setBackgroundImage ( background, for: . normal)
159
+ button. addTarget ( self , action: #selector( openGalleryFromButton) , for: . touchUpInside)
160
+ button. translatesAutoresizingMaskIntoConstraints = false
161
+ return button
162
+ } ( )
163
+
153
164
override public func viewDidLoad( ) {
154
165
super. viewDidLoad ( )
155
166
self . addOrientationDidChangeObserver ( )
@@ -362,9 +373,23 @@ extension CodeScannerView {
362
373
manualCaptureButton. isHidden = !isManualCapture
363
374
}
364
375
376
+ func showManualSelectButton( _ isManualSelect: Bool ) {
377
+ if manualSelectButton. superview == nil {
378
+ view. addSubview ( manualSelectButton)
379
+ NSLayoutConstraint . activate ( [
380
+ manualSelectButton. heightAnchor. constraint ( equalToConstant: 50 ) ,
381
+ manualSelectButton. widthAnchor. constraint ( equalToConstant: 60 ) ,
382
+ view. centerXAnchor. constraint ( equalTo: manualSelectButton. centerXAnchor) ,
383
+ view. safeAreaLayoutGuide. bottomAnchor. constraint ( equalTo: manualSelectButton. bottomAnchor, constant: 32 )
384
+ ] )
385
+ }
386
+
387
+ view. bringSubviewToFront ( manualSelectButton)
388
+ manualSelectButton. isHidden = !isManualSelect
389
+ }
365
390
#endif
366
391
367
- func updateViewController( isTorchOn: Bool , isGalleryPresented: Bool , isManualCapture: Bool ) {
392
+ func updateViewController( isTorchOn: Bool , isGalleryPresented: Bool , isManualCapture: Bool , isManualSelect : Bool ) {
368
393
if let backCamera = AVCaptureDevice . default ( for: AVMediaType . video) ,
369
394
backCamera. hasTorch
370
395
{
@@ -379,6 +404,7 @@ extension CodeScannerView {
379
404
380
405
#if !targetEnvironment(simulator)
381
406
showManualCaptureButton ( isManualCapture)
407
+ showManualSelectButton ( isManualSelect)
382
408
#endif
383
409
}
384
410
0 commit comments