From eedab9acde2425f92268e35703e84436349c9427 Mon Sep 17 00:00:00 2001 From: Sebastian Villena <97059974+ruisebas@users.noreply.github.com> Date: Mon, 8 Jul 2024 15:13:38 -0400 Subject: [PATCH] fix: Using viewDidLayoutSubview instead --- .../Liveness/LivenessViewController.swift | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/Sources/FaceLiveness/Views/Liveness/LivenessViewController.swift b/Sources/FaceLiveness/Views/Liveness/LivenessViewController.swift index 299094b..f0c41a3 100644 --- a/Sources/FaceLiveness/Views/Liveness/LivenessViewController.swift +++ b/Sources/FaceLiveness/Views/Liveness/LivenessViewController.swift @@ -49,11 +49,14 @@ final class _LivenessViewController: UIViewController { super.viewDidLoad() view.backgroundColor = .black layoutSubviews() + setupAVLayer() } - override func viewWillAppear(_ animated: Bool) { - setupAVLayer() - super.viewWillAppear(animated) + override func viewDidLayoutSubviews() { + guard let previewLayer else { return } + previewLayer.frame = cameraFrame + previewLayer.position = view.center + viewModel.cameraViewRect = cameraFrame } private func layoutSubviews() { @@ -71,12 +74,6 @@ final class _LivenessViewController: UIViewController { private func setupAVLayer() { guard previewLayer == nil else { return } - let x = view.frame.minX - let y = view.frame.minY - let width = view.frame.width - let height = width / 3 * 4 - let cameraFrame = CGRect(x: x, y: y, width: width, height: height) - guard let avLayer = viewModel.configureCamera(withinFrame: cameraFrame) else { DispatchQueue.main.async { self.viewModel.livenessState @@ -99,6 +96,17 @@ final class _LivenessViewController: UIViewController { } } + private var cameraFrame: CGRect { + let width = view.frame.width + let height = width / 3 * 4 + return CGRect( + x: view.frame.minX, + y: view.frame.minY, + width: width, + height: height + ) + } + var runningFreshness = false var hasSentClientInformationEvent = false var challengeID = UUID().uuidString