How to Develop Modular Camera Feature with Custom Frame in iOS

How to Develop Modular Camera Feature with Custom Frame in iOSAhmet Fatih AktepeBlockedUnblockFollowFollowingMay 7In this article, we will try to cover development of camera feature in iOS.

The main idea is to develop camera feature as a single module which can be integrated into any app very easily.

In order to accomplish modularity, I developed a singleton called ZCLCameraManager which handles pretty much everything for basic camera usage of any app.

The module consists of three parts; the first one is the manager which will handle every interaction with the camera, second one is focus square and the last one is the delegate which will help us receive photo, video and video thumbnail data from our camera manager.

The best part of this module is that it can initialize a camera for the frame you define.

This will also allow you to change camera frame at runtime depending on your requirement.

At the end of the article, I’ll also add fully functional demo which can be used as an example as well.

Let’s start coding!1- ZCLCameraManager necessary variables;First part consists necessary variables for our camera manager.

Manager also handles application states in order to update camera session configs.

2- ZCLCameraManager Get Methods3- ZCLCameraManager Init Preview MethodMake sure that you set videoGravity as .

resize otherwise iOS will force camera frame to be default which will be the whole screen and won’t let you define a custom frame for your camera preview.

4- ZCLCameraManager Session ConfigurationThe most important thing here is to make sure that you are setting the correct quality settings for the camera otherwise older iOS mobile devices may not be able to satisfy your quality requirement and it will cause app to crash.

In order to prevent this I added a method called setupBestPresetAvailable()This method will help you overcome quality settings issue.

I also added two different configuration methods if you want to use the camera in photo and video mode separately.

Photo Mode Camera Session ConfigurationVideo Mode Camera Session ConfigurationBoth of these functions have completion handler which will help you handle your UI changes better.

Probably another important feature for camera is to be able to switch between front and rear cameras.

The function for this can be found below;As I said at the beginning of the article, the main idea here is to create a camera feature that is portable and easy to integrate.

Some apps require certain quality and dimension standards for their photos, this manager will help you implement these standards very efficiently.

The manager also has delegate functions which can be subscribed by any controller to handle photo and video outputs.

In the example project, I developed the camera view controller that can be initialized from different places of your app which will also help modularization.

ZCLCameraManager can be found here as a full bundle.

You can also find an example project here to test it on your device.

Thanks for reading, happy coding!!.

. More details

Leave a Reply