ALCameraViewController

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

Subscribe to updates I use ALCameraViewController


Statistics on ALCameraViewController

Number of watchers on Github 1608
Number of open issues 34
Average time to close an issue 9 days
Main language Swift
Average time to merge a PR 5 days
Open pull requests 11+
Closed pull requests 25+
Last commit 10 months ago
Repo Created over 3 years ago
Repo Last Updated 8 months ago
Size 1.67 MB
Organization / Authoralexlittlejohn
Latest Release3.0.3
Contributors2
Page Updated
Do you use ALCameraViewController? Leave a review!
View open issues (34)
View ALCameraViewController activity
View on github
Latest Open Source Launches
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating ALCameraViewController for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

ALCameraViewController

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

camera cropper library permissions

Features

  • [x] Front facing and rear facing camera
  • [x] Simple and clean look
  • [x] Custom image picker with permission checking
  • [x] Image cropping
  • [x] Flash light
  • [x] Zoom
  • [x] 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.

ALCameraViewController open issues Ask a question     (View All Issues)
  • about 2 years How do i get the sourceType?
  • about 2 years Hi, this is awesome. Does it support video uploading?
  • about 2 years Sound turns off when accessing camera.
  • about 2 years Can I custom frame for buttons that's overlay on camera
  • about 2 years Is it possible to change the crop size?
  • about 2 years Cancel, Confirm Button order?
  • about 2 years iPad landscape rotation incorrect
  • over 2 years No zooming enabled?
  • over 2 years Square Photo and Video
  • over 2 years Use only the cropper(not the camera)
  • over 2 years Touch feedback for CameraButton
  • over 2 years Remove ConfirmViewController.xib
  • over 2 years Zooming doesn't work on the camera
  • over 2 years Enhancement: Have an option to have the crop added to the photo as an adjustment
  • over 2 years Image picker album selection
  • over 2 years Video recording support
  • over 2 years Select multiple images
  • almost 3 years circular crop overlay
  • almost 3 years Custom rectangular shape crop
ALCameraViewController open pull requests (View All Pulls)
  • Rotate Screen
  • Crop overlay resizing feature
  • Swift3 Xcode 8 Beta 6 + crop resize
  • Camera preview fix
  • Added resizable crop feature
  • Scaling image in the ConfirmViewController
  • Feature/orientationanimation-zoom-exif-errorhandling-scaling
  • Filter
  • Added filter screen
  • Added rectangular and square cropping frame support.
  • Ability of multiple selection on PhotoLibraryViewController
ALCameraViewController list of languages used
ALCameraViewController latest release notes
3.0.3 3.0.3

Fixed issue #247, iPhone X layout Merged PR #254, Fixed cropping issues on front camera

3.0.2 3.0.2

Fixed issue #231

3.0.1 3.0.1

Migrated to Swift 4.0

Other projects in Swift