📸 iMessage-like, Image Picker Controller Provides custom features.

Overview

RAImagePicker

CI Status Version License Platform

Description

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



Overview

Object RAImagePickerController manages user interactions and delivers the results of those interactions to a delegate object.

RAImagePickerController depend on the configuration you set up before presenting it.

Functional Parts:

  1. Action Items(Default Asset.) - Supports two actions, this section is optional and by default contains action item for camera and photos.
  2. Camera - Camera's output(Capture Videos/Photos), this section is optinal and by default it's turned on.
  3. Asset. - Thumbnails of assets found in gallery, this section is mandatory and and can not be turned off.

Protocol Provide a delegate that conforms to RAImagePickerControllerDelegate protocol. Use delegate to get informed when user takes a picture or selects an asset from library and configure custom action and asset collection view cells.

Usage

Follow the following steps to get started:

  1. Add permissions to your info.plist file.
  2. Create new instance of RAImagePickerController.
  3. Present the controller Note: You can configure the controller by set Custom Cells, change Appearance and Layout and the Capture Mode

Features

  • Presentation Design Handeled for .horizontal(like iMessage) and .vertical Modes
  • Portrait and Landscape Supported
  • Support iPhone X
  • Support Live Photos
  • Flip Camera (Rear/Front)
  • Highly and Easly Customisable Layout

Plist Privacy Permissions

In order to get access to the user Camera and Photos/Videos Gallery, you will need to add permissions to the plist file :

  • Privacy - Camera Usage Description (Photos/Videos)
  • Privacy - Photo Library Usage Description (Gallery)
  • Privacy - Microphone Usage Description (Videos)
<key>NSCameraUsageDescription</key>
<string>Access Description</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Access Description</string>
<key>NSMicrophoneUsageDescription</key>
<string>Access Description</string>

Capture Modes

Currently it supports capturing Photos, Live Photos and Videos.

To configure RAImagePicker to support desired media type use captureSettings struct. Use property cameraMode to specify what kind of output you are interested in.

  • photo [Support Photos Only (Default)]
  • video [Support Videos Only]
  • photoAndLivePhoto [Support Photos & Live Photos]
  • photoAndVideo [Support Videos & Photos]

Example:

let imagePicker = RAImagePickerController()
imagePicker.captureSettings.cameraMode = .photoAndLivePhoto

To save the captured photos to the gallery. Set the flag savesCapturedPhotosToPhotoLibrary to true.


Example:

let imagePicker = RAImagePickerController()
imagePicker.captureSettings.savesCapturedPhotosToPhotoLibrary = true

Fetching

Default Image Picker fetches from Photo Library 1000 photos and videos from smart album smartAlbumUserLibrary that should represent Camera Roll album. If you wish to provide your own fetch result please implement image picker controller's assetsFetchResultBlock block.

For example the following code snippet can fetch only live photos:

let imagePicker = RAImagePickerController()
imagePicker.assetsFetchResultBlock = {
    guard let livePhotosCollection = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .smartAlbumLivePhotos, options: nil).firstObject else {
        return nil //you can return nil if you did not find desired fetch result, default fetch result will be used.
    }
    return PHAsset.fetchAssets(in: livePhotosCollection, options: nil)
}

Reference Photos Framework.

Customization



Action Cells

  1. Set Layout Configuration
let imagePicker = RAImagePickerController()
imagePicker.layoutConfiguration.showsDefaultCameraItem  = true
imagePicker.layoutConfiguration.showsDefaultGalleryItem = true
  1. Register Action Cells Now there's multiple ways to register your custom cells
  • Using nib
imagePicker.registerNibForActionItems(CustomNib) 
  • Using class
imagePicker.registerCellClassForActionItems(CustomCell) 
  • For specific item(nib)
imagePicker.cellRegistrator.register(nib: CustomNib, forActionItemAt: 0) 
  • For specific item(class)
imagePicker.cellRegistrator.register(nib: CustomCell, forActionItemAt: 0) 
  1. Configure Delegate
func imagePicker(controller: RAImagePickerController, willDisplayActionItem cell: UICollectionViewCell, at index: Int) {
    switch cell {
    case let customCell as CustomCell:
        switch index {
        case 0:
            customCell.title.text = "Title"
            customCell.icon.image = UIImage(named: "icon_name")
        case 1:
            customCell.title.text = "Title"
            customCell.icon.image = UIImage(named: "icon_name")
        default: break
        }
    default:
        break
    }
}
  1. Handle Selected Assets
func imagePicker(controller: RAImagePickerController, didSelectActionItemAt index: Int) {
    print("Selected Asset. Index: \(index)")
}

Appearance Cells

  1. Register Cell Classes
let imagePicker = RAImagePickerController()
imagePicker.register(cellClass: CustomImageCell.self, forAssetItemOf: .image)
imagePicker.register(cellClass: CustomVideoCell.self, forAssetItemOf: .video)

Please note, that RACellRegistrator provides a method to register one cell or nib for any asset media type.

  1. Configure Delegate
func imagePicker(controller: RAImagePickerController, willDisplayAssetItem cell: RAImagePickerAssetCell, asset: PHAsset) {
    switch cell {
    case let imageCell as CustomImageCell:
        if asset.mediaSubtypes.contains(.photoLive) {
            imageCell.subtypeImageView.image = UIImage(named: "icon_name")
        }
        else if asset.mediaSubtypes.contains(.photoPanorama) {
            imageCell.subtypeImageView.image = UIImage(named: "icon_name")
        }
        else if #available(iOS 10.2, *), asset.mediaSubtypes.contains(.photoDepthEffect) {
            imageCell.subtypeImageView.image = UIImage(named: "icon_name")
        }
        // etc ...
    case let videoCell as CustomVideoCell:
        videoCell.label.text = asset.duration
    default:
        break
    }
}

Presentation

let imagePicker = RAImagePickerController()
navigationController.present(imagePicker, animated: true, completion: nil)

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

References

Requirements

  • Xcode +9.0
  • iOS 10.0+
  • Swift 4

Installation

RAImagePicker is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'RAImagePicker'

Author

rallahaseh, [email protected]

License

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

You might also like...
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 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

📷 multiple phassets picker for iOS lib. like a facebook
📷 multiple phassets picker for iOS lib. like a facebook

Written in Swift 5.0 TLPhotoPicker enables application to pick images and videos from multiple smart album in iOS, similar to the current facebook app

A Shortcuts-like and highly customizable SFSymbol picker written in Swift.
A Shortcuts-like and highly customizable SFSymbol picker written in Swift.

SFTintedIconPicker SFTintedIconPicker is a Shortcuts-like and highly customizable SFSymbol picker written in Swift. Features Native Appearance Search

Custom iOS camera and photo picker with editing capabilities
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

📷 A composable image editor using Core Image and Metal.
📷 A composable image editor using Core Image and Metal.

Brightroom - Composable image editor - building your own UI Classic Image Editor PhotosCrop Face detection Masking component 🎉 v2.0.0-alpha now open!

An image download extension of the image view written in Swift for iOS, tvOS and macOS.
An image download extension of the image view written in Swift for iOS, tvOS and macOS.

Moa, an image downloader written in Swift for iOS, tvOS and macOS Moa is an image download library written in Swift. It allows to download and show an

📷 A composable image editor using Core Image and Metal.
📷 A composable image editor using Core Image and Metal.

Brightroom - Composable image editor - building your own UI Classic Image Editor PhotosCrop Face detection Masking component 🎉 v2.0.0-alpha now open!

AsyncImage before iOS 15. Lightweight, pure SwiftUI Image view, that displays an image downloaded from URL, with auxiliary views and local cache.

URLImage URLImage is a SwiftUI view that displays an image downloaded from provided URL. URLImage manages downloading remote image and caching it loca

AYImageKit is a Swift Library for Async Image Downloading, Show Name's Initials and Can View image in Separate Screen.
AYImageKit is a Swift Library for Async Image Downloading, Show Name's Initials and Can View image in Separate Screen.

AYImageKit AYImageKit is a Swift Library for Async Image Downloading. Features Async Image Downloading. Can Show Text Initials. Can have Custom Styles

Comments
  • Not able to get the camera capture image

    Not able to get the camera capture image

    I am have added RAImagePicker via pod in a project. Also I have refering the Sample example given by you. But not able to get the image capture by camera.

    I am using Xcode 9.2 and iOS 11.0 log.txt

    opened by ios-dev-newbie 0
Owner
Rashed Al-Lahaseh
Software Engineer (iOS) - Swift - Objective-C
Rashed Al-Lahaseh
A carousel of stacked items as seen in iMessage for photos

StackedItemsCarousel A carousel of stacked items (such as photos) as seen in iMessage What? iMessage on iOS 15 shows multiple photos in a carousel of

Andreas Verhoeven 5 Sep 30, 2022
📸 Instagram-like image picker & filters for iOS

YPImagePicker YPImagePicker is an instagram-like photo/video picker for iOS written in pure Swift. It is feature-rich and highly customizable to match

Yummypets 4k Dec 27, 2022
Image picker with custom crop rect for iOS written in Swift (Ported over from GKImagePicker)

WDImagePicker Ever wanted a custom crop area for the UIImagePickerController? Now you can have it with WDImagePicker. Just set your custom crop area a

Wu Di 96 Dec 19, 2022
FlexibleImage is implemented with the hope that anyone could easily develop an app that provides features such as Camera Filter and Theme.

FlexibleImage is implemented with the hope that anyone could easily develop an app that provides features such as Camera Filter and Theme. When you wr

Jungwon An 815 Dec 30, 2022
An instagram-like image editor that can apply preset filters passed to it and customized editings to a binded image.

CZImageEditor CZImageEditor is an instagram-like image editor with clean and intuitive UI. It is pure swift and can apply preset filters and customize

null 8 Dec 16, 2022
Jogendra 113 Nov 28, 2022
FMPhotoPicker is a modern, simple and zero-dependency photo picker with an elegant and customizable image editor

FMPhotoPicker is a modern, simple and zero-dependency photo picker with an elegant and customizable image editor Quick demo Batch select/deselect Smoo

Cong Nguyen 648 Dec 27, 2022
📹 Your next favorite image and video picker

Description We all love image pickers, don't we? You may already know of ImagePicker, the all in one solution for capturing pictures and selecting ima

HyperRedink 1.4k Dec 25, 2022
A very useful and unique iOS library to open image picker in just few lines of code.

ImagePickerEasy A very simple solution to implement UIImagePickerController() in your application. Requirements Swift 4.2 and above Installation Image

wajeehulhassan 6 May 13, 2022
FLImagePicker - A simple image picker supported multiple selection

FLImagePicker A simple image picker supported multiple selection. Features Multiple selection Gesture supported Dark mode Easy modification Installati

Allen Lee 4 Aug 17, 2022