Gif Camera Controller is a camera output that takes successive photos to create GIFs.
- Full camera functionality
- Control frames per second
Instantiate a GifCameraController
and run setupSession()
in a do-catch statement. To see the camera's preview use a GifCameraPreview
view.
Note that GifCameraPreview
is currently not supported in interface builder. You must instantiate in code.
var gifCamera: GifCameraController!
var previewView: GifCameraPreviewView!
self.gifCamera = GifCameraController()
do {
if try self.gifCamera.setupSession() {
self.gifCamera.setPreviewView(self.previewView)
}
} catch let error as NSError {
self.gifCamera = nil
print(error.localizedDescription)
}
Then set the duration and frames per second.
self.gifCamera.maxDuration = 2.0
self.gifCamera.framesPerSecond = 3
Begin the capture session and start recording.
self.gifCamera.startSession()
self.gifCaemra.startRecording()
When recording finishes, the delegate will output the frames.
var delegate: GifCameraControllerDelegate
The delegate for the camera controller. This must be set.
var maxDuration: Double
The maximum duration of the gif. Defaults to 4 seconds.
var framesPerSecond: Int
The capture rate of the camera. Defaults to 18 fps.
var currentDevicePosition: AVCaptureDevicePosition
The current device position. (read-only)
func setupSession() throws -> Bool
Setup the camera controller. This must be called before the sessiong begins.
func setPreviewView(view: GifCameraPreviewView)
Adds a preview view to the camera controller. You must instantiate GifCameraPreviewView
in code.
func startSession()
Starts the capture session.
func stopSession()
Stops the capture session.
func isRecording() -> Bool
Returns if session is recording.
func startRecording()
Starts recording.
func pauseRecording()
Pauses recording. Does not reset current parameters.
func cancelRecording()
Stops recording and resets all variables.
func stopRecording()
Ends the recording.
func toggleCamera()
Toggles between the front camera and the back. Note GifCameraController
defaults to the front camera.
func toggleTorch(forceKill forceKill: Bool) -> Bool
Toggles the torch and returns if the torch is on. Set forceKill to true to turn off the torch.
func cameraController(cameraController: GifCameraController, didFinishRecordingWithFrames frames: [CGImage], withTotalDuration duration: Double)
Returns to the delegate the bitmaps the frames along with the duration of the gif. This is called with stopRecording()
or when maxDuration
is reached.
func cameraController(cameraController: GifCameraController, didAppendFrameNumber index: Int)
Notifies the delegate that a frame was appended.
To run the example project, clone the repo, and run pod install
from the Example directory first.
- Swift 3.0+
- iOS 9.0+
GifCameraController is available through CocoaPods. To install it, simply add the following line to your Podfile:
use_frameworks!
pod "GifCameraController"
Lawrence Tran
See the LICENSE file for more info.