Skip to content

Commit a44d427

Browse files
authored
Revert "Added animation on path update and corner only path for QR-code frame"
1 parent cc19d63 commit a44d427

3 files changed

Lines changed: 18 additions & 192 deletions

File tree

Sources/SPQRCode/Interface/SPQRCameraController+AVCaptureMetadataOutputObjectsDelegate.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ extension SPQRCameraController: AVCaptureMetadataOutputObjectsDelegate {
3535
guard let transformedObject = previewLayer.transformedMetadataObject(for: object) as? AVMetadataMachineReadableCodeObject else { return }
3636

3737
let points = transformedObject.corners
38+
guard let firstPoint = points.first else { return }
39+
let path = UIBezierPath()
40+
path.move(to: firstPoint)
41+
var newPoints = points
42+
newPoints.removeFirst()
43+
newPoints.append(firstPoint)
44+
newPoints.forEach { path.addLine(to: $0) }
3845

3946
// Update Detail
4047

@@ -84,7 +91,7 @@ extension SPQRCameraController: AVCaptureMetadataOutputObjectsDelegate {
8491

8592
// Update Frame
8693

87-
frameLayer.update(using: points)
94+
frameLayer.update(with: path)
8895

8996
// Timer
9097

Sources/SPQRCode/Interface/SPQRCorner.swift

Lines changed: 0 additions & 126 deletions
This file was deleted.

Sources/SPQRCode/Interface/SPQRFrameLayer.swift

Lines changed: 10 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -23,86 +23,31 @@
2323
import UIKit
2424

2525
class SPQRFrameLayer: CAShapeLayer {
26-
private let cLength: CGFloat
27-
private let cRadius: CGFloat
2826

2927
// MARK: - Init
3028

31-
init(
32-
length: CGFloat = 16.0,
33-
radius: CGFloat = 16.0,
34-
lineWidth: CGFloat = 5.0,
35-
lineColor: UIColor = .systemYellow
36-
) {
37-
self.cLength = length
38-
self.cRadius = radius
39-
29+
override init() {
4030
super.init()
41-
42-
self.strokeColor = lineColor.cgColor
43-
self.fillColor = UIColor.clear.cgColor
44-
45-
self.lineWidth = lineWidth
31+
strokeColor = UIColor.systemYellow.cgColor
32+
lineWidth = 5
33+
fillColor = UIColor.clear.cgColor
4634
}
4735

4836
required init?(coder: NSCoder) {
4937
fatalError("init(coder:) has not been implemented")
5038
}
5139

52-
override func action(forKey event: String) -> CAAction? {
53-
if event == "path" {
54-
let animation: CABasicAnimation = .init(keyPath: event)
55-
56-
animation.duration = 0.3
57-
animation.timingFunction = CATransaction.animationTimingFunction()
58-
59-
return animation
60-
}
61-
62-
return super.action(forKey: event)
63-
}
64-
6540
// MARK: - Actions
6641

67-
func update(using points: [CGPoint]) {
68-
let corners = buildCorners(for: points)
69-
70-
let framePath: UIBezierPath = .init()
71-
72-
for corner in corners {
73-
guard let cStartPoint = corner.startPoint(using: corners),
74-
let cPreCurvePoint = corner.preCurvePoint(using: corners),
75-
let cPostCurvePoint = corner.postCurvePoint(using: corners),
76-
let cEndPoint = corner.endPoint(using: corners)
77-
else { return }
78-
79-
framePath.move(to: cStartPoint)
80-
framePath.addLine(to: cPreCurvePoint)
81-
framePath.addQuadCurve(to: cPostCurvePoint, controlPoint: corner.point)
82-
framePath.addLine(to: cEndPoint)
83-
}
84-
85-
path = framePath.cgPath
42+
func detected(with newBezierPath: UIBezierPath) {
43+
path = newBezierPath.cgPath
8644
}
8745

88-
func dissapear() {
89-
path = nil
46+
func update(with newBezierPath: UIBezierPath) {
47+
path = newBezierPath.cgPath
9048
}
9149

92-
private func buildCorners(for points: [CGPoint]) -> [SPQRCorner] {
93-
var corners: [SPQRCorner] = .init()
94-
95-
for corner in SPQRCorner.Kind.allCases {
96-
corners.append(
97-
.init(
98-
kind: corner,
99-
point: points[corner.rawValue],
100-
length: cLength,
101-
radius: cRadius
102-
)
103-
)
104-
}
105-
106-
return corners
50+
func dissapear() {
51+
path = nil
10752
}
10853
}

0 commit comments

Comments
 (0)