//스크린 화면을 터치시 포커스 잡아주는 메서드
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touchPoint = touches.first! as UITouch
// view1 = > 카메라 스크린 view
let screenSize = view1.bounds.size
let focusPoint = CGPoint(x: touchPoint.location(in: view1).y / screenSize.height, y: 1.0 - touchPoint.location(in: view1).x / screenSize.width)
if let device = AVCaptureDevice.default(for: AVMediaType.video) {
do {
try device.lockForConfiguration()
if device.isFocusPointOfInterestSupported {
device.focusPointOfInterest = focusPoint
device.focusMode = AVCaptureDevice.FocusMode.autoFocus
}
if device.isExposurePointOfInterestSupported {
device.exposurePointOfInterest = focusPoint
device.exposureMode = AVCaptureDevice.ExposureMode.autoExpose
}
device.unlockForConfiguration()
} catch {
// Handle errors here
}
}
}