Search code examples
iosswiftavcapturesession

How to remove screen "flash" effect from an AVCaptureSession captureStillImageAsynchronouslyFromConnection


I see that it's impossible to remove the shutter sound that comes with an avcapturesession captureStillImageAsynchronouslyFromConnection, but I'm not seeing people trying to remove the sort of screen flash that comes with it as well.

You take a picture, the screen gets bright for a second (Not an actual flash) and then returns to its normal brightness.

It looks like Instagram is using an avcapturesession and does not have that screen flash.

https://developer.apple.com/library/content/samplecode/AVCam/Introduction/Intro.html

I looked through this ^ which is what I'm using in my app and I don't see it referenced anywhere. I assume it's some property I have to mess with?

Any helps appreciated.


Solution

  • First of all, you shouldn't use AVCaptureStillImageOutput which owns captureStillImageAsynchronouslyFromConnection method, because it is deprecated. Use AVCapturePhotoOutput instead.

    Second, the Apple's example you refer to has the following snippet in CameraViewController.swift that implements 'flashing':

    self.previewView.videoPreviewLayer.opacity = 0
    UIView.animate(withDuration: 0.25) { [unowned self] in
        self.previewView.videoPreviewLayer.opacity = 1
    }
    

    So just remove/comment it out and you'll be fine.