LoginSignup
2
0

More than 5 years have passed since last update.

AVFoundationを使ったカメラの実装:撮影時に暗転させる

Posted at

iOS標準のカメラアプリは撮影時にViewを暗転させています。
暗転によって、ユーザに撮影したタイミングを伝えているのではないかと考え実現しました。

確認した環境

iOS11

実装

extension CameraViewController: AVCapturePhotoCaptureDelegate{
    func photoOutput(_ output: AVCapturePhotoOutput, willCapturePhotoFor resolvedSettings: AVCaptureResolvedPhotoSettings) {
        cameraFoundationView.alpha = 0
    }
    func photoOutput(_ output: AVCapturePhotoOutput, didCapturePhotoFor resolvedSettings: AVCaptureResolvedPhotoSettings) {
        UIView.animate(withDuration: 0.3, animations: {[weak self] in
            self?.cameraFoundationView.alpha = 1
        })
    }
}

showCameraPreviewLayerlayerAVCaptureVideoPreviewLayer をインサートしています。

iOS標準のカメラアプリの挙動を確認したところ、暗転する時は瞬時に行われ、戻る時に時間がかかっていたのでこのような実装にしました。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0