Skip to content

Commit 6021f61

Browse files
authored
Merge pull request #50 from icefall/master
Barcode focus view styling choosing
2 parents dd11244 + 60da5f1 commit 6021f61

3 files changed

Lines changed: 41 additions & 15 deletions

File tree

BarcodeScanner.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
2DBF9E0E1F169DEF006B5AA8 /* FocusViewType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DBF9E0D1F169DEF006B5AA8 /* FocusViewType.swift */; };
1011
D50BE3E91C9FE7A80000A34C /* flashOff@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = D50BE3E51C9FE7A80000A34C /* flashOff@3x.png */; };
1112
D50BE3EA1C9FE7A80000A34C /* flashOn@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = D50BE3E61C9FE7A80000A34C /* flashOn@3x.png */; };
1213
D50BE3EB1C9FE7A80000A34C /* info@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = D50BE3E71C9FE7A80000A34C /* info@3x.png */; };
@@ -19,6 +20,7 @@
1920
/* End PBXBuildFile section */
2021

2122
/* Begin PBXFileReference section */
23+
2DBF9E0D1F169DEF006B5AA8 /* FocusViewType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FocusViewType.swift; sourceTree = "<group>"; };
2224
D50BE3E51C9FE7A80000A34C /* flashOff@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "flashOff@3x.png"; sourceTree = "<group>"; };
2325
D50BE3E61C9FE7A80000A34C /* flashOn@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "flashOn@3x.png"; sourceTree = "<group>"; };
2426
D50BE3E71C9FE7A80000A34C /* info@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "info@3x.png"; sourceTree = "<group>"; };
@@ -85,6 +87,7 @@
8587
D5FC8AD61D252A12004BED88 /* State.swift */,
8688
D5C4E08C1CA0BFB9008D9269 /* InfoView.swift */,
8789
D5C4E08D1CA0BFB9008D9269 /* TorchMode.swift */,
90+
2DBF9E0D1F169DEF006B5AA8 /* FocusViewType.swift */,
8891
D5F1C1C51C9C5113001E17A6 /* Config.swift */,
8992
D5F1C1C61C9C5113001E17A6 /* BarcodeScannerController.swift */,
9093
D5F1C1D21C9C5809001E17A6 /* HeaderView.swift */,
@@ -178,6 +181,7 @@
178181
D5F1C1D31C9C5809001E17A6 /* HeaderView.swift in Sources */,
179182
D5F1C1C91C9C5113001E17A6 /* Config.swift in Sources */,
180183
D5F1C1CA1C9C5113001E17A6 /* BarcodeScannerController.swift in Sources */,
184+
2DBF9E0E1F169DEF006B5AA8 /* FocusViewType.swift in Sources */,
181185
D5FC8AD71D252A12004BED88 /* State.swift in Sources */,
182186
);
183187
runOnlyForDeploymentPostprocessing = 0;

Sources/BarcodeScannerController.swift

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ open class BarcodeScannerController: UIViewController {
125125
})
126126
}
127127
}
128+
129+
public var barCodeFocusViewType: FocusViewType = .animated
128130

129131
/// The current torch mode on the capture device.
130132
var torchMode: TorchMode = .off {
@@ -202,7 +204,14 @@ open class BarcodeScannerController: UIViewController {
202204
name: NSNotification.Name.UIApplicationWillEnterForeground,
203205
object: nil)
204206
}
205-
207+
208+
open override func viewWillAppear(_ animated: Bool) {
209+
super.viewWillAppear(animated)
210+
setupFrame()
211+
212+
headerView.isHidden = !isBeingPresented
213+
}
214+
206215
open override func viewDidAppear(_ animated: Bool) {
207216
super.viewDidAppear(animated)
208217
animateFocusView()
@@ -300,15 +309,14 @@ open class BarcodeScannerController: UIViewController {
300309
flashButton.alpha = alpha
301310
settingsButton.isHidden = status.state != .unauthorized
302311
}
303-
312+
304313
// MARK: - Layout
305-
open override func viewWillLayoutSubviews() {
306-
super.viewWillLayoutSubviews()
307-
314+
315+
func setupFrame() {
308316
headerView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: 64)
309317
flashButton.frame = CGRect(x: view.frame.width - 50, y: 73, width: 37, height: 37)
310318
infoView.frame = infoFrame
311-
319+
312320
if let videoPreviewLayer = videoPreviewLayer {
313321
videoPreviewLayer.frame = view.layer.bounds
314322
if let connection = videoPreviewLayer.connection, connection.isVideoOrientationSupported {
@@ -322,7 +330,11 @@ open class BarcodeScannerController: UIViewController {
322330
}
323331
}
324332

325-
center(subview: focusView, inSize: CGSize(width: 218, height: 150))
333+
if barCodeFocusViewType == .oneDimension {
334+
center(subview: focusView, inSize: CGSize(width: 280, height: 80))
335+
} else {
336+
center(subview: focusView, inSize: CGSize(width: 218, height: 150))
337+
}
326338
center(subview: settingsButton, inSize: CGSize(width: 150, height: 50))
327339

328340
headerView.isHidden = !isBeingPresented
@@ -376,14 +388,17 @@ open class BarcodeScannerController: UIViewController {
376388
func animateFocusView() {
377389
focusView.layer.removeAllAnimations()
378390
focusView.isHidden = false
379-
380-
UIView.animate(withDuration: 1.0, delay:0,
381-
options: [.repeat, .autoreverse, .beginFromCurrentState],
382-
animations: {
383-
self.center(subview: self.focusView, inSize: CGSize(width: 280, height: 80))
384-
}, completion: nil)
385-
386-
view.setNeedsLayout()
391+
392+
setupFrame()
393+
394+
if barCodeFocusViewType == .animated {
395+
UIView.animate(withDuration: 1.0, delay:0,
396+
options: [.repeat, .autoreverse, .beginFromCurrentState],
397+
animations: {
398+
self.center(subview: self.focusView, inSize: CGSize(width: 280, height: 80))
399+
}, completion: nil)
400+
}
401+
view.setNeedsLayout()
387402
}
388403

389404
// MARK: - Actions

Sources/FocusViewType.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import UIKit
2+
3+
public enum FocusViewType {
4+
case animated
5+
case oneDimension
6+
case twoDimensions
7+
}

0 commit comments

Comments
 (0)