@@ -25,7 +25,7 @@ public class CameraView: UIView {
2525
2626 public func startSession( ) {
2727 session = AVCaptureSession ( )
28- session. sessionPreset = AVCaptureSessionPresetPhoto
28+ session. sessionPreset = AVCaptureSession . Preset . photo
2929
3030 device = cameraWithPosition ( position: currentPosition)
3131 if let device = device , device. hasFlash {
@@ -107,7 +107,7 @@ public class CameraView: UIView {
107107 addGestureRecognizer ( pinchGesture)
108108 }
109109
110- internal func focus( gesture: UITapGestureRecognizer ) {
110+ @ objc internal func focus( gesture: UITapGestureRecognizer ) {
111111 let point = gesture. location ( in: self )
112112
113113 guard focusCamera ( toPoint: point) else {
@@ -141,7 +141,7 @@ public class CameraView: UIView {
141141 } )
142142 }
143143
144- internal func pinch( gesture: UIPinchGestureRecognizer ) {
144+ @ objc internal func pinch( gesture: UIPinchGestureRecognizer ) {
145145 guard let device = device else { return }
146146
147147 // Return zoom value between the minimum and maximum zoom values
@@ -175,16 +175,14 @@ public class CameraView: UIView {
175175 private func createPreview( ) {
176176
177177 preview = AVCaptureVideoPreviewLayer ( session: session)
178- preview. videoGravity = AVLayerVideoGravityResizeAspectFill
178+ preview. videoGravity = AVLayerVideoGravity . resizeAspectFill
179179 preview. frame = bounds
180180
181181 layer. addSublayer ( preview)
182182 }
183183
184- private func cameraWithPosition( position: AVCaptureDevicePosition ) -> AVCaptureDevice ? {
185- guard let devices = AVCaptureDevice . devices ( withMediaType: AVMediaTypeVideo) as? [ AVCaptureDevice ] else {
186- return nil
187- }
184+ private func cameraWithPosition( position: AVCaptureDevice . Position ) -> AVCaptureDevice ? {
185+ let devices = AVCaptureDevice . devices ( for: AVMediaType . video)
188186 return devices. filter { $0. position == position } . first
189187 }
190188
@@ -218,7 +216,7 @@ public class CameraView: UIView {
218216 return false
219217 }
220218
221- let focusPoint = preview. captureDevicePointOfInterest ( for : toPoint)
219+ let focusPoint = preview. captureDevicePointConverted ( fromLayerPoint : toPoint)
222220
223221 device. focusPointOfInterest = focusPoint
224222 device. focusMode = . continuousAutoFocus
@@ -258,11 +256,11 @@ public class CameraView: UIView {
258256 session. beginConfiguration ( )
259257 session. removeInput ( currentInput)
260258
261- if currentInput. device. position == AVCaptureDevicePosition . back {
262- currentPosition = AVCaptureDevicePosition . front
259+ if currentInput. device. position == AVCaptureDevice . Position . back {
260+ currentPosition = AVCaptureDevice . Position . front
263261 device = cameraWithPosition ( position: currentPosition)
264262 } else {
265- currentPosition = AVCaptureDevicePosition . back
263+ currentPosition = AVCaptureDevice . Position . back
266264 device = cameraWithPosition ( position: currentPosition)
267265 }
268266
@@ -283,16 +281,16 @@ public class CameraView: UIView {
283281 }
284282 switch UIApplication . shared. statusBarOrientation {
285283 case . portrait:
286- preview? . connection. videoOrientation = AVCaptureVideoOrientation . portrait
284+ preview? . connection? . videoOrientation = AVCaptureVideoOrientation . portrait
287285 break
288286 case . portraitUpsideDown:
289- preview? . connection. videoOrientation = AVCaptureVideoOrientation . portraitUpsideDown
287+ preview? . connection? . videoOrientation = AVCaptureVideoOrientation . portraitUpsideDown
290288 break
291289 case . landscapeRight:
292- preview? . connection. videoOrientation = AVCaptureVideoOrientation . landscapeRight
290+ preview? . connection? . videoOrientation = AVCaptureVideoOrientation . landscapeRight
293291 break
294292 case . landscapeLeft:
295- preview? . connection. videoOrientation = AVCaptureVideoOrientation . landscapeLeft
293+ preview? . connection? . videoOrientation = AVCaptureVideoOrientation . landscapeLeft
296294 break
297295 default : break
298296 }
0 commit comments