FaceCamViewer – An iOS Control That Displays A Live Camera Window Similar To FaceTime.

My latest creation is an iOS control that displays a live camera feed embedded in a UIView. Its very similar to the front camera view that you see when using FaceTime, Skype or Tango. I’ve posted the code on Github so feel free to fork it, modify it and use it however you want.

Source Code: https://github.com/ijason/FaceCamTest

To use the control, the first thing you need to do is add references to AVFoundation.framework and QuartzCore.framework. Copy FaceCamViewer.h and FaceCamViewer.h into your project and add #import "FaceCamViewer.h" where you want to display the camera feed. Add the following code to use the control:

FaceCamViewer *viewer = [[FaceCamViewer alloc] initWithDeviceType:IPHONE3x5];
[viewer startFaceCam];
[self.view addSubview:viewer];

The initWithDevice method has three possible values: IPHONE3x5, IPHONE4 and IPAD.

  • IPHONE3x5 sets a predefined location for iPhone devices with 3.5 inch screens.
  • IPHONE4 is for iPhone devices with 4 inch screens.
  • IPAD is for iPads of course.

[viewer startFaceCam]; starts the camera feed and [self.view addSubview:viewer]; adds the control to your view.

Options

By default, FaceCamViewer will use the front camera but you can set it to the back camera with the following line of code:

viewer.cameraType = AVCaptureDevicePositionBack;

You can allow the viewer to be dragged by user touch by setting the draggable option:

viewer.draggable = YES;

In addition, if you do not want to use any of predefined locations, you can create your own by initializing the control like this:

FaceCamViewer *viewer = [[FaceCamViewer alloc] initWithFrame:CGRectMake(190, 290, 120, 160)];

You also have the option of using your own AVCaptureSession by setting it yourself:

AVCaptureSession *session = [[AVCaptureSession alloc] init];
viewer.session = session; 

Feel free to download the code and improve on it however way you want.

FaceCamViewer

Leave a Reply

Your email address will not be published. Required fields are marked *

Please Do the Math      
 

*