Add grid, camera focus
This commit is contained in:
@ -20,6 +20,8 @@ class CameraManager: ObservableObject {
|
||||
private let photoOutput = AVCapturePhotoOutput()
|
||||
private var status = Status.unconfigured
|
||||
|
||||
private var camera: AVCaptureDevice?
|
||||
|
||||
private init() {
|
||||
configure()
|
||||
}
|
||||
@ -67,11 +69,11 @@ class CameraManager: ObservableObject {
|
||||
session.commitConfiguration()
|
||||
}
|
||||
|
||||
let device = AVCaptureDevice.default(
|
||||
self.camera = AVCaptureDevice.default(
|
||||
.builtInWideAngleCamera,
|
||||
for: .video,
|
||||
position: .back)
|
||||
guard let camera = device else {
|
||||
guard let camera = camera else {
|
||||
set(error: .cameraUnavailable)
|
||||
status = .failed
|
||||
return
|
||||
@ -169,4 +171,28 @@ class CameraManager: ObservableObject {
|
||||
self.photoOutput.capturePhoto(with: photoSettings, delegate: delegate)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Focus
|
||||
|
||||
func continuouslyFocusOnMiddle() {
|
||||
guard let device = camera else {
|
||||
return
|
||||
}
|
||||
do {
|
||||
try device.lockForConfiguration()
|
||||
|
||||
if device.isFocusPointOfInterestSupported {
|
||||
device.focusPointOfInterest = CGPoint(x: 0.5, y: 0.5)
|
||||
device.focusMode = .continuousAutoFocus
|
||||
}
|
||||
print("Enabled continuous autofocus")
|
||||
device.unlockForConfiguration()
|
||||
} catch {
|
||||
self.error("Could not lock device for configuration: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension CameraManager: Logger {
|
||||
|
||||
}
|
||||
|
@ -87,7 +87,8 @@ struct CameraView: View {
|
||||
.overlay(RoundedRectangle(cornerRadius: circleSize/2)
|
||||
.stroke(lineWidth: circleStrength)
|
||||
.foregroundColor(circleColor))
|
||||
|
||||
.onTapGesture(perform: didTapCircle)
|
||||
.background(Color(white: 1, opacity: 0.01))
|
||||
Spacer()
|
||||
}
|
||||
Spacer()
|
||||
@ -116,6 +117,10 @@ struct CameraView: View {
|
||||
private func capture() {
|
||||
model.captureImage()
|
||||
}
|
||||
|
||||
private func didTapCircle() {
|
||||
model.continuouslyFocusOnMiddle()
|
||||
}
|
||||
}
|
||||
|
||||
struct CameraView_Previews: PreviewProvider {
|
||||
|
@ -54,4 +54,8 @@ class ContentViewModel: ObservableObject {
|
||||
func captureImage() {
|
||||
cameraManager.capturePhoto(delegate: frameManager)
|
||||
}
|
||||
|
||||
func continuouslyFocusOnMiddle() {
|
||||
cameraManager.continuouslyFocusOnMiddle()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user