Skip to content

Commit e3073a7

Browse files
committed
many type of animation type views
1 parent 42b3701 commit e3073a7

3 files changed

Lines changed: 35 additions & 11 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: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ open class BarcodeScannerController: UIViewController {
126126
}
127127
}
128128

129-
public var shouldAnimateFocusView: Bool = true
129+
public var barCodeFocusViewType: FocusViewType = .animated
130130

131131
/// The current torch mode on the capture device.
132132
var torchMode: TorchMode = .off {
@@ -324,7 +324,11 @@ open class BarcodeScannerController: UIViewController {
324324
}
325325
}
326326

327-
center(subview: focusView, inSize: CGSize(width: 218, height: 150))
327+
if barCodeFocusViewType == .twoDimentions {
328+
center(subview: focusView, inSize: CGSize(width: 218, height: 150))
329+
} else {
330+
center(subview: focusView, inSize: CGSize(width: 280, height: 80))
331+
}
328332
center(subview: settingsButton, inSize: CGSize(width: 150, height: 50))
329333

330334
headerView.isHidden = !isBeingPresented
@@ -379,15 +383,14 @@ open class BarcodeScannerController: UIViewController {
379383
focusView.layer.removeAllAnimations()
380384
focusView.isHidden = false
381385

382-
if shouldAnimateFocusView {
383-
UIView.animate(withDuration: 1.0, delay:0,
384-
options: [.repeat, .autoreverse, .beginFromCurrentState],
385-
animations: {
386-
self.center(subview: self.focusView, inSize: CGSize(width: 280, height: 80))
387-
}, completion: nil)
388-
}
389-
390-
view.setNeedsLayout()
386+
if barCodeFocusViewType == .animated {
387+
UIView.animate(withDuration: 1.0, delay:0,
388+
options: [.repeat, .autoreverse, .beginFromCurrentState],
389+
animations: {
390+
self.center(subview: self.focusView, inSize: CGSize(width: 280, height: 80))
391+
}, completion: nil)
392+
}
393+
view.setNeedsLayout()
391394
}
392395

393396
// MARK: - Actions

Sources/FocusViewType.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// FocusViewType.swift
3+
// BarcodeScanner
4+
//
5+
// Created by Carl Brusell on 12/07/17.
6+
// Copyright © 2017 Hyper Interaktiv AS. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
public enum FocusViewType {
12+
13+
case animated
14+
case oneDimention
15+
case twoDimentions
16+
17+
}

0 commit comments

Comments
 (0)