Overlaying image on AVCaptureStillImageOutput

Currently I am working in an app that captures still im…

Currently I am working in an app that captures still images using AVFoundation. One of the requirements for this app is to overlap an image with the Preview Layer. Looked around but there was not much documentation about this. I was thinking of creating a different class for controlling only this image.

There was no need to do that and the solution is rather easy.

For this we do not need to touch the class which controls the preview layer (AVCaptureVideoPreviewLayer). Instead we just create a UIImageView ivar

@implementation MyViewController
    UIImageView *overlayImageView;

In my case my app loads a frame in two different view controllers once the image(the frame) is created. In this particular case, the
frame comes from a Singleton that is holding the image, but this code works by replacing just to the name of the image, string or whatever
is being used.

My method that loads and overlays the Preview Layer looks like this:

  DataController *dataController = [DataController sharedInstance];
  overlayImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:dataController.result]];
  [overlayImageView setFrame:CGRectMake(0, 64, 320,372)]; //set size. it is possible to just substract values from nav bar and tool bar to support any device. 
 [[self view] addSubview:overlayImageView]; // just add the over lay uiimageview to self view
   [[captureManager captureSession] startRunning];

As result we get the preview with the overlaying image displaying in the view controller.