Skip to content

Commit

Permalink
fix: Using viewDidLayoutSubview instead
Browse files Browse the repository at this point in the history
  • Loading branch information
ruisebas committed Jul 8, 2024
1 parent 46ab0a4 commit eedab9a
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions Sources/FaceLiveness/Views/Liveness/LivenessViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit eedab9a

Please sign in to comment.