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
Library for iOS Camera API. Massively increase performance and ease of use within your next iOS Project.

CameraKit helps you add reliable camera to your app quickly. Our open source camera platform provides consistent capture results, service that scales,

CameraKit 628 Dec 27, 2022
A better way to operate QR Code in Swift, support iOS, macOS, watchOS and tvOS.

EFQRCode is a lightweight, pure-Swift library for generating stylized QRCode images with watermark or icon, and for recognizing QRCode from images, in

EFPrefix 4.3k Jan 2, 2023
🛰 CoreLocation Made Easy - Efficient & Easy Location Tracker, IP Location, Gecoder, Geofence, Autocomplete, Beacon Ranging, Broadcaster and Visits Monitoring

Location Manager Made Easy SwiftLocation is a lightweight Swift Library that provides an easy way to work with location-related functionalities. No mo

Daniele Margutti 3.2k Dec 30, 2022
:mag_right: A simple and beautiful barcode scanner.

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 3, 2023
Get the data from Accelerometer, Gyroscope and Magnetometer in only Two or a few lines of code.

Get the data from Accelerometer, Gyroscope and Magnetometer in only Two or a few lines of code. CoreMotion now made insanely simple :octocat: :satellite:

Muhammad Haroon Baig 1.1k Nov 16, 2022
Simply the fastest way to transmit data between iOS/tvOS and OSX

DarkLightning DarkLightning is a lightweight Swift library to allow data transmission between iOS/tvOS devices (Lightning port, Dock connector, USB-C)

Jens Meder 318 Nov 29, 2022
Swift library to easily check the current device and some more info about it.

Usage To run the example project, clone the repo, and run pod install from the Example directory first. let device = Deviice.current device is a Devi

Andrea Mario Lufino 56 Nov 3, 2022
Luminous provides you a lot of information about the system and a lot of handy methods to quickly get useful data on the iOS platform.

Luminous Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements iOS 8+ Swift 5 Xcode 1

Andrea Mario Lufino 324 Nov 27, 2022
Light weight tool for detecting the current device and screen size written in swift.

Device detect the current  device model and screen size. Installation CocoaPods Device is available through CocoaPods. To install it, simply add the

Lucas Ortis 1.5k Dec 28, 2022
WatchCon is a tool which enables creating easy connectivity between iOS and WatchOS.

WatchCon WatchCon is a tool which enables creating easy connectivity between iOS and WatchOS Requirements iOS 9.0+ / watchOS 2.0+ CocoaPods CocoaPods

Abdullah Selek 33 Sep 22, 2022
NFC Forum Well Known Type Data Parser for iOS11 and Core NFC

NFCNDEFParse NFC Forum Well Known Type Data Parser for iOS11 and Core NFC. Supports parsing of types: Text - NFCForum-TS-RTD_Text_1.0 2006-07-24 Uri -

Jari Kalinainen 14 Oct 21, 2022
Lightweight Cocoa library for detecting the running device's model and screen size.

Lightweight Cocoa library for detecting the running device's model and screen size. With the newer  devices, developers have more work to do. This li

Sebastian Dobrincu 1.3k Nov 24, 2022
Writes twitter and contact (links) to writable nfcs on iPhone 7+ iOS 14+

nfc writer ios app nfc writer app is a hacky fun side project that writes twitter and contact (links) to writable nfcs. runs on iPhone 7+ iOS 14+. joi

Vivian Phung 5 Nov 23, 2022
A camera view controller with custom image picker and image cropping.

ALCameraViewController A camera view controller with custom image picker and image cropping. Features Front facing and rear facing camera Simple and c

Alex Littlejohn 2k Dec 29, 2022
📸 iMessage-like, Image Picker Controller Provides custom features.

RAImagePicker Description RAImagePicker is a protocol-oriented framework that provides custom features from the built-in Image Picker Edit. Overview O

Rashed Al-Lahaseh 14 Aug 18, 2022
YiVideoEditor is a library for rotating, cropping, adding layers (watermark) and as well as adding audio (music) to the videos.

YiVideoEditor YiVideoEditor is a library for rotating, cropping, adding layers (watermark) and as well as adding audio (music) to the videos. YiVideoE

coderyi 97 Dec 14, 2022
Custom iOS camera and photo picker with editing capabilities

Overview Paparazzo is a component for picking and editing photos. Key Features ?? Taking photos using camera ?? Picking photos from user's photo libra

avito.tech 757 Jan 4, 2023
DGCropImage - A photo cropping tool which mimics Photo.app written by Swift

DGCropImage A photo cropping tool which mimics Photo.app written by Swift. This

donggyu 11 Jul 14, 2022
Use any custom view as custom callout view for MKMapView with cool animations. Use any image as annotation view.

MapViewPlus About MapViewPlus gives you the missing methods of MapKit which are: imageForAnnotation and calloutViewForAnnotationView delegate methods.

Okhan Okbay 162 Nov 16, 2022
FlaneurImagePicker is an iOS image picker that allows users to pick images from different sources (ex: user's library, user's camera, Instagram...). It's highly customizable.

FlaneurImagePicker is a highly customizable iOS image picker that allows users to pick images from different sources (ex: device's library, device's c

FlaneurApp 17 Feb 2, 2020