Skip to content

Commit eedab9a

Browse files
committed
fix: Using viewDidLayoutSubview instead
1 parent 46ab0a4 commit eedab9a

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

Sources/FaceLiveness/Views/Liveness/LivenessViewController.swift

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@ final class _LivenessViewController: UIViewController {
4949
super.viewDidLoad()
5050
view.backgroundColor = .black
5151
layoutSubviews()
52+
setupAVLayer()
5253
}
5354

54-
override func viewWillAppear(_ animated: Bool) {
55-
setupAVLayer()
56-
super.viewWillAppear(animated)
55+
override func viewDidLayoutSubviews() {
56+
guard let previewLayer else { return }
57+
previewLayer.frame = cameraFrame
58+
previewLayer.position = view.center
59+
viewModel.cameraViewRect = cameraFrame
5760
}
5861

5962
private func layoutSubviews() {
@@ -71,12 +74,6 @@ final class _LivenessViewController: UIViewController {
7174

7275
private func setupAVLayer() {
7376
guard previewLayer == nil else { return }
74-
let x = view.frame.minX
75-
let y = view.frame.minY
76-
let width = view.frame.width
77-
let height = width / 3 * 4
78-
let cameraFrame = CGRect(x: x, y: y, width: width, height: height)
79-
8077
guard let avLayer = viewModel.configureCamera(withinFrame: cameraFrame) else {
8178
DispatchQueue.main.async {
8279
self.viewModel.livenessState
@@ -99,6 +96,17 @@ final class _LivenessViewController: UIViewController {
9996
}
10097
}
10198

99+
private var cameraFrame: CGRect {
100+
let width = view.frame.width
101+
let height = width / 3 * 4
102+
return CGRect(
103+
x: view.frame.minX,
104+
y: view.frame.minY,
105+
width: width,
106+
height: height
107+
)
108+
}
109+
102110
var runningFreshness = false
103111
var hasSentClientInformationEvent = false
104112
var challengeID = UUID().uuidString

0 commit comments

Comments
 (0)