Giter Site home page Giter Site logo

narlei / cameramanager Goto Github PK

View Code? Open in Web Editor NEW

This project forked from imaginary-cloud/cameramanager

0.0 2.0 0.0 4.41 MB

Simple Swift class to provide all the configurations you need to create custom camera view in your app

License: Other

Ruby 1.22% Objective-C 0.84% Swift 97.95%

cameramanager's Introduction

Camera Manager

CocoaPods Carthage compatible

This is a simple Swift class to provide all the configurations you need to create custom camera view in your app. It follows orientation change and updates UI accordingly, supports front and rear camera selection, pinch to zoom, tap to focus, different flash modes, inputs and outputs. Just drag, drop and use.

Now it's compatible with latest Swift syntax, so if you're using any Swift version prior to 4.0 make sure to use one of the previously tagged releases.

Installation with CocoaPods

The easiest way to install the CameraManager is with: CocoaPods

Podfile

If you want Swift 4.0 syntax use:

use_frameworks!

pod 'CameraManager', '~> 4.0'

If you want Swift 3.0 syntax use:

use_frameworks!

pod 'CameraManager', '~> 3.2'

If you want Swift 2.0 syntax use:

use_frameworks!

pod 'CameraManager', '~> 2.2'

If you want Swift 1.2 syntax use:

use_frameworks!

pod 'CameraManager', '~> 1.0.14'

Installation with Swift Package Manager

The Swift Package Manager is a tool for managing the distribution of Swift code.

Add CameraManager as a dependency in your Package.swift file:

import PackageDescription

let package = Package(
    dependencies: [
        .Package(url: "https://github.com/imaginary-cloud/CameraManager", majorVersion: 4, minor: 0)
    ]
)

Installation with Carthage

Carthage is another dependency management tool written in Swift.

Add the following line to your Cartfile:

If you want Swift 4.0 syntax use:

github "imaginary-cloud/CameraManager" >= 4.0

If you want Swift 3.0 syntax use:

github "imaginary-cloud/CameraManager" >= 3.2

If you want Swift 2.0 syntax use:

github "imaginary-cloud/CameraManager" >= 2.2

If you want Swift 1.2 syntax use:

github "imaginary-cloud/CameraManager" >= 1.0

And run carthage update to build the dynamic framework.

How to use

To use it you just add the preview layer to your desired view, you'll get back the state of the camera if it's unavailable, ready or the user denied access to it. Have in mind that in order to retain the AVCaptureSession you will need to retain cameraManager instance somewhere, ex. as an instance constant.

let cameraManager = CameraManager()
cameraManager.addPreviewLayerToView(self.cameraView)

You can set input device to front or back camera:

cameraManager.cameraDevice = .Front
cameraManager.cameraDevice = .Back

You can specify if the front camera image should be horizontally fliped:

cameraManager.shouldFlipFrontCameraImage = true

You can enable or disable gestures on camera preview:

cameraManager.shouldEnableTapToFocus = true
cameraManager.shouldEnablePinchToZoom = true

You can set output format to Image, video or video with audio:

cameraManager.cameraOutputMode = .StillImage
cameraManager.cameraOutputMode = .VideoWithMic
cameraManager.cameraOutputMode = .VideoOnly

You can set the quality:

cameraManager.cameraOutputQuality = .Low
cameraManager.cameraOutputQuality = .Medium
cameraManager.cameraOutputQuality = .High

You can specifiy the focus and exposure mode:

cameraManager.focusMode = .continuousAutoFocus 
cameraManager.exposureMode = .continuousAutoExposure 

You can change the flash mode (it will also set corresponding flash mode):

cameraManager.flashMode = .Off
cameraManager.flashMode = .On
cameraManager.flashMode = .Auto

To enable location services for storing in Camera Roll. Default is false:

cameraManager.shouldUseLocationServices = true

To check if the device supports flash call:

cameraManager.hasFlash

To change flash mode to the next available one you can use this handy function which will also return current value for you to update the UI accordingly:

cameraManager.changeFlashMode()

You can specify if you want to save the files to phone library:

cameraManager.writeFilesToPhoneLibrary = true

You can specify if you want to disable animations:

cameraManager.animateShutter = false
cameraManager.animateCameraDeviceChange = false

You can specify if you want the user to be asked about camera permissions automatically when you first try to use the camera or manually:

cameraManager.showAccessPermissionPopupAutomatically = false

You can even setUp your custom block to handle error messages: It can be customized to be presented on the Window root view controller, for example.

cameraManager.showErrorBlock = { (erTitle: String, erMessage: String) -> Void in
    var alertController = UIAlertController(title: erTitle, message: erMessage, preferredStyle: .Alert)
    alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: { (alertAction) -> Void in
    }))

    let topController = UIApplication.sharedApplication().keyWindow?.rootViewController

    if (topController != nil) {
        topController?.presentViewController(alertController, animated: true, completion: { () -> Void in
            //
        })
    }

}

To shoot image all you need to do is call:

cameraManager.capturePictureWithCompletion({ (image, error) -> Void in
	self.myImage = image             
})

To record video you do:

cameraManager.startRecordingVideo()
cameraManager.stopVideoRecording({ (videoURL, error) -> Void in
	NSFileManager.defaultManager().copyItemAtURL(videoURL, toURL: self.myVideoURL, error: &error)
})

Support

Supports iOS 8 and above. Xcode 9.0 is required to build the latest code written in Swift 4.0.

License

Copyright © 2017 ImaginaryCloud, imaginarycloud.com. This library is licensed under the MIT license.

cameramanager's People

Contributors

agiletalk avatar aukaost avatar davidortinau avatar davidy avatar dimohamdy avatar dpereira411 avatar elikohen avatar gamafranco avatar gbmksquare avatar iamtomcat avatar jakubmazur avatar jasonlagaac avatar joelfsreis avatar lexrus avatar miguelcampiao avatar narlei avatar nelanelanela avatar rivera-ernesto avatar songjiaqiang avatar timothyqiu avatar torrao avatar xc0der avatar zaubara avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.