ALCameraViewController - A camera view controller with custom image picker and image cropping.

Overview

ALCameraViewController

A camera view controller with custom image picker and image cropping.

camera cropper library permissions

Features

  • Front facing and rear facing camera
  • Simple and clean look
  • Custom image picker with permission checking
  • Image cropping
  • Flash light
  • Zoom
  • Tap to focus

Installation & Requirements

This project requires Xcode 9 to run and compiles with swift 4

Note: This library makes use of the AVFoundation camera API's which are unavailable on the iOS simulator. You'll need a real device to run it.

CocoaPods: Add the following to your Podfile:

pod 'ALCameraViewController'

For swift 3.2 support

pod 'ALCameraViewController', '~> 2.0.3'

Carthage:

github "alexlittlejohn/ALCameraViewController"

Privacy (iOS 10)

If you are building your app with iOS 10 or newer, you need to add two privacy keys to your app to allow the usage of the camera and photo library, or your app will crash.

Add the keys below to your Info.plist, adding strings with the description you want to provide when prompting the user.

    NSPhotoLibraryUsageDescription
    NSCameraUsageDescription

Usage

To use this component couldn't be simpler. Add import ALCameraViewController to the top of your controller file.

In the viewController

let cameraViewController = CameraViewController { [weak self] image, asset in
	// Do something with your image here.
	self?.dismiss(animated: true, completion: nil)
}

present(cameraViewController, animated: true, completion: nil)

Parameters

There are a number of configurable options available for CameraViewController

init(croppingParameters: CroppingParameters = CroppingParameters(),
     allowsLibraryAccess: Bool = true,
     allowsSwapCameraOrientation: Bool = true,
     allowVolumeButtonCapture: Bool = true,
     completion: @escaping CameraViewCompletion)

The Cropping Parameters struct accepts the following parameters

init(isEnabled: Bool = false,
     allowResizing: Bool = true,
     allowMoving: Bool = true,
     minimumSize: CGSize = CGSize(width: 60, height: 60))

The success parameter returns a UIImage? and a PHAsset? for more advanced use cases. If the user canceled photo capture then both of these options will be nil

typealias CameraViewCompletion = (UIImage?, PHAsset?) -> Void

Note: To prevent retain cycles, it is best to use a [weak self] reference within the success parameter

Other usage options

You can also instantiate the image picker component by itself as well.

let croppingEnabled = true

/// Provides an image picker wrapped inside a UINavigationController instance
let imagePickerViewController = CameraViewController.imagePickerViewController(croppingEnabled: croppingEnabled) { [weak self] image, asset in
		// Do something with your image here.
	 	// If cropping is enabled this image will be the cropped version

    self?.dismiss(animated: true, completion: nil)
}

present(imagePickerViewController, animated: true, completion: nil)

For more control you can create it directly.

Note: This approach requires some familiarity with the PhotoKit library provided by apple

import Photos

let imagePickerViewController = PhotoLibraryViewController()
imagePickerViewController.onSelectionComplete = { asset in

		// The asset could be nil if the user doesn't select anything
		guard let asset = asset else {
			return
		}

    // Provides a PHAsset object
		// Retrieve a UIImage from a PHAsset using
		let options = PHImageRequestOptions()
    options.deliveryMode = .highQualityFormat
    options.isNetworkAccessAllowed = true

		PHImageManager.default().requestImage(for: asset, targetSize: PHImageManagerMaximumSize, contentMode: .aspectFill, options: options) { image, _ in
        if let image = image {
						// Do something with your image here
        }
    }
}

present(imagePickerViewController, animated: true, completion: nil)

License

ALCameraViewController is available under the MIT license. See the LICENSE file for more info.

Comments
  • Rotate Screen

    Rotate Screen

    Big changes at all. Now, CameraView can rotate the layer and any button of CameraViewController will rotate when you rotate the screen. Btw, what do you think, when the device is landscape, to move the close button to bottom of gallery button? I think it is more concise and maintain the flow of the layout. It is better to use with tablets too.

    Enhancement WIP 
    opened by ppamorim 25
  • Supported fork fixing iOS 13 issue

    Supported fork fixing iOS 13 issue

    Check out the commits for more details. Main point of this fork is the iOS 13 compatibility: I fixed the cropping area resizing issue.

    @AlexLittlejohn Please tell me if you want to go on with the support, I would be glad to provide more help and to remove my fork.

    Meanwhile, people can also use the pod I made:

    pod 'ALCameraViewController-Tulleb', '~> 3.1'

    opened by Tulleb 15
  • AutoLayout

    AutoLayout

    Hi Alex! I implemented the AutoLayout on the ALCameraViewController. What do you think about this implementation? I think it is most correct way to create the layout. If you discover any problem, say it to me. Please don't close if it has any problem, notifies me and I will try to fix.

    Thanks!

    opened by ppamorim 10
  • Added resizable cropping area feature

    Added resizable cropping area feature

    This PR add the resizable cropping area feature.

    Closes #15. Update of #192.

    It also:

    • Removed the default Team ID.
    • Changed the view order into Confirmation View in order to always be able to tap on confirm & cancel buttons.
    • Added an option to disable the feature.
    • Defined a minimum area to crop (@ameli90) and added an option to change it.

    Left to do later on:

    • Prevent user to crop outside of the image bounds.
    Enhancement 
    opened by Tulleb 8
  • Added convenience initializer that adds ability to hide library picker

    Added convenience initializer that adds ability to hide library picker

    I decided to make the initializer a convenience one, as it doesn't really do anything different than init(croppingEnabled: Bool, completion: ALCameraViewCompletion), in terms of initialization. The convenience initializer simply calls that one and sets the library button to be both disabled and hidden.

    opened by Satre95 3
  • Swift3 Xcode 8 Beta 6 + crop resize

    Swift3 Xcode 8 Beta 6 + crop resize

    Swift 3 compatibility.

    There is currently no swift3 branch @AlexLittlejohn. If you prefer to create one then I can resubmit another PR to merge this on this new branch.

    Closes #122.

    EDIT: This also add a new feature to edit the cropped area frame.

    Closes #15.

    Cropped area is resizable Returned image don't have to be a square anymore

    opened by Tulleb 2
  • Swift3 Xcode 8 Beta 5

    Swift3 Xcode 8 Beta 5

    Swift 3 compatibility.

    There is currently no swift3 branch @AlexLittlejohn. If you create one then I can create another PR for this new branch.

    Closes #122.

    opened by Tulleb 2
  • Removed the cameraQueue due to race condition and redundant reloadData

    Removed the cameraQueue due to race condition and redundant reloadData

    Reload Data

    Removed the reloadData dispatch due it not being necessary as well as messing up the order of the images if you repeatedly go back in the image picker.

    In order to trigger this go into the image picker a few times and you will notice the thumbnails move around, if you select the image you will get the correct one. This seems to be triggered by the reloadData.

    It also appears unnecessary as the collectionView will build the cells when you designate the delegate and dataSource.

    Camera Queue

    Removed the cameraQueue as it was creating a race condition and might cause the application to crash if you open the image picker and close it fast enough.

    Since the createPreview() method is not on the queue, the stopSession method can be called in between the the createPreview method and session.startRunning(). This will cause session to invalidate and crash the application as session is nil.

    opened by radumihaiu 2
  • Add ability to localize all texts used in framework

    Add ability to localize all texts used in framework

    This pull-request is intended to add possibility to localize texts used in framework.

    To use that feature one should add CameraView.strings file to the project and localize it as usual.

    In case if such file is not provided in the main bundle all the texts fall back to original version.

    opened by f33dm3m0m 1
  • Fix unsubscribing from notifications

    Fix unsubscribing from notifications

    After dismissing CameraViewController it still can react to volume changes either with physical buttons or after playing video (which shoots AVSystemController_SystemVolumeDidChangeNotification).

    The problem can be solved by unsubscribing from notifications and nullifying volumeControl property in viewWillDisappear method of CameraViewController.

    This pull-request does exactly that.

    opened by f33dm3m0m 1
  • restart camera if photo confirmation was canceled

    restart camera if photo confirmation was canceled

    This little PR restarts the camera session if the user has canceled the photo confirmation.

    Before there was a black screen after the cancellation and the user could only restart the camera session by pulling down the CameraViewController a little bit. In that case viewWillAppear was called again restarting the camera session.

    opened by cyBerta 0
  • Allow CameraViewController to be used in a navigation stack without losing completion

    Allow CameraViewController to be used in a navigation stack without losing completion

    When the CameraViewController is on a Navigation Stack, a picture is taken, and a new ViewController is pushed on the stack, when you hit back to return to the CameraViewController, the completion no longer exists and can no longer be called, making it impossible to leave the CameraViewController. We removed clearing out the completion blocks. This should be ok and not leave retain cycles because the presenting CameraViewController has the only reference to the completion.

    opened by SuperWes 0
Releases(3.1)
  • 3.1(Oct 16, 2019)

    • Fixed iOS 13 compatibility issue with the crop overlay not being resizable (#301).
    • Upgrade to Swift 5.
    • Bumped iOS minimum compatibility from 8 to 9 in order to rework on the crop overlay system (now using auto-layout).
    • Some more minor fixes and improvements...
    Source code(tar.gz)
    Source code(zip)
  • 3.0.3(Jan 24, 2018)

  • 3.0.2(Oct 2, 2017)

  • 3.0.1(Sep 27, 2017)

  • 2.0.2(Sep 8, 2017)

  • 2.0.1(Sep 6, 2017)

  • 2.0.0(Sep 4, 2017)

    [This release contains breaking behaviour changes]

    • Added the option to resize the crop overlay by dragging from the corners
      • Setting the minimum crop area is also available
    Source code(tar.gz)
    Source code(zip)
  • 1.4.1(Aug 30, 2017)

    • Added pinch to zoom #214
    • Added the option to disable the volume buttons for capturing images. #214
      • Use this if you want audio to remain playing in the background.
    Source code(tar.gz)
    Source code(zip)
  • 1.4.0(Jul 29, 2017)

    • Add ability to disable the camera orientation swap button
    • Skip saving to and loading from library access if allow library access
    • Crop correctly in portrait orientation with library access off
    • Fixed other orientations. The only one that worked before was portrait
    • Refactor cropping code to remove duplication - Jason
    • Fix orientation of resized image - Jason & Wes
    • Fix orientation of images show in preview from front camera
    Source code(tar.gz)
    Source code(zip)
  • 1.3.1(Apr 10, 2017)

  • 1.2.7(Oct 16, 2016)

  • 1.2.6(Oct 14, 2016)

  • 1.2.3(Aug 31, 2016)

  • 1.2.2(Jul 8, 2016)

  • CarthageFix(Apr 2, 2016)

  • 1.1.9(Apr 2, 2016)

  • 1.1.8(Apr 2, 2016)

  • 1.1.6(Feb 21, 2016)

    • Fixes issue with rotated images and cropping
    • Allow images to be requested from iCloud if they are not available locally
    • Added a workaround for an apple bug with PHAsset pixel dimensions detailed here: http://www.openradar.me/21045111
    Source code(tar.gz)
    Source code(zip)
  • 1.1.4(Feb 21, 2016)

    • Photos capture using the camera will now be saved to the camera roll
    • Greatly improved memory usage when requesting and cropping large images
    • Tap to focus support has been added when cropping is not enabled
    • The flash now has an automatic mode
    • Pressing either of the volume keys will now take a picture
    Source code(tar.gz)
    Source code(zip)
Owner
Alex Littlejohn
iOS Developer/Swiftier/Schwifty
Alex Littlejohn
Simple Swift class to provide all the configurations you need to create custom camera view in your app

Camera Manager This is a simple Swift class to provide all the configurations you need to create custom camera view in your app. It follows orientatio

Imaginary Cloud 1.3k Dec 29, 2022
Custom camera with AVFoundation. Beautiful, light and easy to integrate with iOS projects.

?? Warning This repository is DEPRECATED and not maintained anymore. Custom camera with AVFoundation. Beautiful, light and easy to integrate with iOS

Tudo Gostoso Internet 1.4k Dec 16, 2022
NextLevel is a Swift camera system designed for easy integration, customized media capture, and image streaming in iOS

NextLevel is a Swift camera system designed for easy integration, customized media capture, and image streaming in iOS. Integration can optionally leverage AVFoundation or ARKit.

NextLevel 2k Jan 2, 2023
This plugin defines a global navigator.camera object, which provides an API for taking pictures and for choosing images from the system's image library.

title description Camera Take pictures with the device camera. AppVeyor Travis CI cordova-plugin-camera This plugin defines a global navigator.camera

null 0 Nov 2, 2021
A camera designed in Swift for easily integrating CoreML models - as well as image streaming, QR/Barcode detection, and many other features

Would you like to use a fully-functional camera in an iOS application in seconds? Would you like to do CoreML image recognition in just a few more sec

David Okun 868 Dec 29, 2022
ScanBarcodes is a SwiftUI view that scans barcodes using an iPhone or iPad camera.

ScanBarcodes ScanBarcodes is a SwiftUI view that scans barcodes using an iPhone or iPad camera. The framework uses AVFoundation for high performance v

NASA Jet Propulsion Laboratory 6 Nov 29, 2022
BarcodeScanner is a simple and beautiful wrapper around the camera with barcode capturing functionality and a great user experience.

Description BarcodeScanner is a simple and beautiful wrapper around the camera with barcode capturing functionality and a great user experience. Barco

HyperRedink 1.6k Jan 7, 2023
Instagram-like photo browser and a camera feature with a few line of code in Swift.

Fusuma is a Swift library that provides an Instagram-like photo browser with a camera feature using only a few lines of code.

Yuta Akizuki 2.4k Dec 31, 2022
A fully customisable and modern camera implementation for iOS made with AVFoundation.

Features Extremely simple and easy to use Controls autofocus & exposure Customizable interface Code-made UI assets that do not lose resolution quality

Gabriel Alvarado 1.3k Nov 30, 2022
Fasttt and easy camera framework for iOS with customizable filters

FastttCamera is a wrapper around AVFoundation that allows you to build your own powerful custom camera app without all the headaches of using AVFounda

IFTTT 1.8k Dec 10, 2022
An iOS framework that uses the front camera, detects your face and takes a selfie.

TakeASelfie An iOS framework that uses the front camera, detects your face and takes a selfie. This api opens the front camera and draws an green oval

Abdullah Selek 37 Jan 3, 2023
Video and photo camera for iOS

Features: Description Records video ?? takes photos ?? Flash on/off ⚡ Front / Back camera ↕️ Hold to record video ✊ Tap to take photo ?? Tap to focus

André J 192 Dec 17, 2022
UIView+CameraBackground - Show camera layer as a background to any UIView.

UIView+CameraBackground Show camera layer as a background to any UIView. Features Both front and back camera supported. Flash modes: auto, on, off. Co

Yonat Sharon 63 Nov 15, 2022
iOS camera engine with Vine-like tap to record, animatable filters, slow motion, segments editing

SCRecorder A Vine/Instagram like audio/video recorder and filter framework in Objective-C. In short, here is a short list of the cool things you can d

Simon Corsin 3.1k Dec 25, 2022
A simple, customizable camera control - video recorder for iOS.

LLSimpleCamera: A simple customizable camera - video recorder control LLSimpleCamera is a library for creating a customized camera - video recorder sc

Ömer Faruk Gül 1.2k Dec 12, 2022
A light weight & simple & easy camera for iOS by Swift.

DKCamera Description A light weight & simple & easy camera for iOS by Swift. It uses CoreMotion framework to detect device orientation, so the screen-

Bannings 86 Aug 18, 2022
Camera engine for iOS, written in Swift, above AVFoundation. :monkey:

?? The most advanced Camera framework in Swift ?? CameraEngine is an iOS camera engine library that allows easy integration of special capture feature

Remi ROBERT 575 Dec 25, 2022
A Snapchat Inspired iOS Camera Framework written in Swift

Overview SwiftyCam is a a simple, Snapchat-style iOS Camera framework for easy photo and video capture. SwiftyCam allows users to capture both photos

Andrew Walz 2k Dec 21, 2022
Mock UIImagePickerController for testing camera based UI in simulator

Mock UIImagePickerController to simulate the camera in iOS simulator.

Yonat Sharon 18 Aug 18, 2022