in FastViTSample/FastViTSample/ViewfinderView.swift [57:77]
func coordinateRotation() {
guard let input = session?.inputs.first as? AVCaptureDeviceInput else {
rotationCoordinator = nil
rotationObservation = nil
return
}
rotationCoordinator = AVCaptureDevice.RotationCoordinator(
device: input.device,
previewLayer: layer
)
previewLayer.connection?.videoRotationAngle = rotationCoordinator!.videoRotationAngleForHorizonLevelPreview
rotationObservation = rotationCoordinator!.observe(
\.videoRotationAngleForHorizonLevelPreview,
options: .new
) { [unowned self] _, change in
guard let angle = change.newValue else { return }
self.previewLayer.connection?.videoRotationAngle = angle
}
}