DTPhotoViewerController - A fully customizable photo viewer ViewController to display single photo or collection of photos, inspired by Facebook photo viewer.

Overview

DTPhotoViewerController

Version License Platform

Example

Screenshot

Demo video: https://youtu.be/aTLx4M4zsKk

DTPhotoViewerController is very simple to use, if you want to display only one image in the photo viewer, all you need to do is to pass UIImageView and UIImage instances:

if let viewController = DTPhotoViewerController(referencedView: imageView, image: image) {
    self.presentViewController(viewController, animated: true, completion: nil)
}

For multiple images, what you have to do is providing an dataSource to the DTPhotoViewerController instance. DTPhotoViewerControllerDataSource has three required methods and one optional method, here is an example how to implement them which is also available in the Demo:

func photoViewerController(_ photoViewerController: DTPhotoViewerController, referencedViewForPhotoAt index: Int) -> UIView? {
    let indexPath = IndexPath(item: index, section: 0)
    if let cell = self.collectionView?.cellForItem(at: indexPath) as? CollectionViewCell {
        return cell.imageView
    }

    return nil
}

func numberOfItems(in photoViewerController: DTPhotoViewerController) -> Int {
    return images.count
}

func photoViewerController(_ photoViewerController: DTPhotoViewerController, configureCell cell: DTPhotoCollectionViewCell, forPhotoAt index: Int) {
     // You need to implement this method usually when using custom DTPhotoCollectionViewCell and configure each photo differently.
}

func photoViewerController(_ photoViewerController: DTPhotoViewerController, configurePhotoAt index: Int, withImageView imageView: UIImageView) {
    imageView.image = images[index]
}

In case you want to add more UI elements to each photo, the best way is to create a subclass of DTPhotoCollectionViewCell and then call either one of these methods registerClassPhotoViewer: or registerNibForPhotoViewer:

if let viewController = BDFPostPhotoViewerController(referencedView: cell.imageView, image: cell.imageView.image) {
     viewController.registerClassPhotoViewer(DTCustomPhotoCollectionViewCell.self)
}

There is also delegate(DTPhotoViewerControllerDelegate) if you want to customize the behavior of DTPhotoViewerController.

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

Requirements

Installation

CocoaPods

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

For Swift 5:

pod "DTPhotoViewerController"

For Swift 4.2:

pod 'DTPhotoViewerController', '~> 1.2.5'

Swift package manager

DTPhotoViewerController is available for SPM from version 3.0.2. Add the following to the dependencies of your Package.swift:

.package(url: "https://github.com/tungvoduc/DTPhotoViewerController", from: "version")

Author

Tung Vo, [email protected]

License

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

Feedbacks & requests

  • Open an issue if you find a bug, make a proposal or simply need some help.
  • You can also contact me via email.
Comments
  • One cell. CGSize(width: view.frame.width, height: 300)

    One cell. CGSize(width: view.frame.width, height: 300)

    How to apply your method if a collection with one visible image is installed on the screen. For example, when you increase the isolation and after you wind up the collection and stop at the 3 index, after you close the picture and on this day the collection would wind up to the desired index

    opened by sLm-s 8
  • RTL referencedViewForPhotoAt issue

    RTL referencedViewForPhotoAt issue

    @tungvoduc it's me again with the RTL :)

    Could you please have a look on referencedViewForPhotoAt method with the RTL layout. It returns invalid index, Thanks again!

    opened by a-hasan 6
  • There is an issue here.

    There is an issue here.

    There is an issue here.

    1. In landscape view on iPhone x, the image is pushed a few pixels to the right.
    2. If you rotate the screen after zooming in, the position will not come out properly.
    bug 
    opened by eastswift 6
  • swift 3 Cannot inherit from non-open class 'DTPhotoCollectionViewCell' outside of its defining module

    swift 3 Cannot inherit from non-open class 'DTPhotoCollectionViewCell' outside of its defining module

    "In case you want to add more UI elements to each photo, the best way is to create a subclass of DTPhotoCollectionViewCell and then call either one of these methods registerClassPhotoViewer: or registerNibForPhotoViewer:"

    Im using cocoapods, hence I cannot subclassed the DTPhotoCollectionViewCell, error above

    opened by jofax 6
  • Unable to build with SPM

    Unable to build with SPM

    It looks like the framework comes with SPM support (great!), but when I try to build there are numerous errors. I have several other libraries managed by SPM and they work without an issue...

    I'm importing the library via Xcode 11's UI. Also fwiw I can build it just fine with Carthage.

    opened by danqing 4
  • Delegate and datasource use in UIViewController Class

    Delegate and datasource use in UIViewController Class

    How can i get the delegate response in UiViewController class? See my code here, I want to add cancel button on the top of the left corner. I am using BDFPostPhotoViewerController.swift file.

    Here is my Image Tapped Function where i initialise the class, i want to show/hide cross button on corner when image zoom or zoom out.

    screen shot 2017-08-04 at 4 18 49 pm

    i tried to use like this but here is some error. See screenshot screen shot 2017-08-04 at 4 50 31 pm

    Please help me. Thanks

    opened by ErAshu 4
  • Load image from link

    Load image from link

    func photoViewerController(_ photoViewerController: DTPhotoViewerController, configurePhotoAt index: Int, withImageView imageView: UIImageView) {
        imageView.pin_setImage(from: images[index].link?.toURL, [placeholderImage:](url) cell.imageView.image)
        }
      }
    

    when loading image i zoom imageView and when loaded image this is change zoomscale

    opened by phucdth12a 3
  • DTPhotoViewerController crashes the application

    DTPhotoViewerController crashes the application

    My application crashes if I use the full size image in the following delegate:

    func photoViewerController(_ photoViewerController: DTPhotoViewerController, configurePhotoAt 
    index: Int, withImageView imageView: UIImageView) {
         imageView.image = images[index].image
    }
    

    But if I reduce the size of image, the problem is not there. It crashes after I scroll about 50 images. The console says that out of memory. So I think the application is out of memory when I am using heavy images.

    opened by amrit42087 3
  • Problem wit UIStackView

    Problem wit UIStackView

    I build a nice gallery UITableViewCell displaying a vary of Images using UIStackViews. This works fine and looks good...

    But when I now want to show you PhotoViewerController I get some problems :(

    That why you simple hide the referenceView. And when you do this, the UIStackView removes it and updates the constraints.

    Any changes to change this to not hide the referenceView?

    opened by Urkman 3
  • Add annotations to fix availability warnings

    Add annotations to fix availability warnings

    When integrating DTPhotoViewerConroller into a project using Swift Package Manager and Xcode 11 you get warnings about UIViewPropertyAnimator only being available in iOS 10+. Adding availability annotations fixes those errors and allows you to build the project.

    opened by addisonwebb 2
  • How can i present PhotoLibrary without referenceView

    How can i present PhotoLibrary without referenceView

    I am trying to download from url's some photos and it seems that the referenceView is required.

    Is there a way to have optional the referencedView? because sometimes referenceView is not always available (action from text to open a remote image for example)

    (i have subclassed DTPhotoViewerController and added activityIndicator to hide when download completes)

    opened by alexookah 2
  • Image Rotate/Flip Automatically

    Image Rotate/Flip Automatically

    I have copied your classes into my project. Some images are rotating/flipping automatically when I open them in DTPhotoViewer. Can you please help me to fix this issue? @tungvoduc

    opened by 24Lathiya 2
  • Status bar not hidden

    Status bar not hidden

    Hi, i've added this line: override var prefersStatusBarHidden: Bool { return true } in debug mode the setter is called, but the status isn't hidden. Is there another way to hide the status bar when the photo viewer is displayed?

    Thank you

    opened by furiosFast 0
  • How to get the current image?

    How to get the current image?

    I wanted to update a label that I placed inside a custom DTPhotoViewerController everytime user swipes to reveal new photo. I stored the data to the image's identifier. How can I access the current presented image?

    I tried self.imageView.image but it returns only the first image every time.

    Edit: Yes I did try to follow the example but I wanted to hide/unhide this label (just like the close and save button from the example) along with other elements that I've placed.

    opened by kxvn-lx 0
  • Add dismiss delegate methods

    Add dismiss delegate methods

    I'd like to get notified when the viewer is dismissed interactively. Currently there's no way to get notified.

    The reason I need it is I'm playing video in the photo viewer, and I want to stop it when the viewer is dismissed.

    opened by danqing 3
  • Expose current cell in a method

    Expose current cell in a method

    I'm subclassing DTPhotoViewController to add support for video, and I noticed that there's no method that exposes the currently visible collection view cell.

    This is problematic for me because I need to access the cell in order to configure the AVPlayer instance I added to it. I can't do it in configureCell method because it's possible for a user to scroll a bit and then give up (thus returning to the previous cell), but other methods don't pass in the cell instance.

    I suppose I can cast scrollView to UICollectionView and use that, but that's not future-proof. Can we have a way to access the current cell?

    Thank you!

    opened by danqing 1
Owner
Tung Vo
A passionate iOS developer.
Tung Vo
Simple PhotoBrowser/Viewer inspired by facebook, twitter photo browsers written by swift

SKPhotoBrowser [![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-) Simple PhotoBrowser

keishi suzuki 2.4k Jan 6, 2023
Jogendra 113 Nov 28, 2022
An iOS/tvOS photo gallery viewer, useful for viewing a large (or small!) number of photos.

This project is unmaintained. Alex passed away in an accident in late 2019. His love of iOS development will always be remembered. AXPhotoViewer AXPho

Alex Hill 596 Dec 30, 2022
Source code for iOS app "Photos for VK" — albums and photos manager for social network VKontakte

VK Photos (formally Photos for VK) VK Photos is an iOS app for manage albums and photos in social network VKontakte (vk.com) Screenshots Disclaimer ⚠️

Yury S. 29 Oct 8, 2022
A photo gallery for iOS with a modern feature set. Similar features as the Facebook photo browser.

EBPhotoPages ”A photo gallery can become a pretty complex component of an app very quickly. The EBPhotoPages project demonstrates how a developer coul

Eddy Borja 1.7k Dec 8, 2022
PhotoEditor SDK: A fully customizable photo editor for your app.

About PhotoEditor SDK for iOS Our SDK provides tools for adding photo editing capabilities to your iOS application with a big variety of filters that

IMG.LY 116 Jan 1, 2023
FacebookImagePicker is Facebook album photo picker written in Swift.

Features • Installation • Usage • Translation • License GBHFacebookImagePicker is Facebook's album photo picker written in Swift, built to provide a s

Florian Gabach 231 Dec 17, 2022
An iOS app that helps you check, edit and delete metadata of photos, including but not limited to EXIF, TIFF...

MetaX A simple iOS app that helps you check, edit and delete metadata of photos, including but not limited to EXIF, TIFF... Feature List main metadata

Yuhan Chen 189 Dec 29, 2022
iOS app to automagically control device torch/flash and capture photos

BlobStar ✨ Version française ???? iOS application to automagically control the device torch/flash and capture photos. The software was quickly drafted

Ninja Inc 1 Oct 11, 2021
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
Starter project for Mars rover photos iOS app.

MarzyPan is an app that allows users to view photos taken by Mars rovers during their time on the planet. This is a starter project that has some UI

Ruben Hansen-Rojas 0 Dec 30, 2021
UnsplashPhotosApp - Photos app using Unsplash API

UnsplashPhotosApp If you like this open-source project please consider supportin

Watery Desert 27 Dec 18, 2022
FlickrSearchPhotos - Simple search photos application which uses Flickr REST API made in Swift

FlickrSearchPhotos - Simple search photos application which uses Flickr REST API made in Swift

 Mihai Erős 1 Jun 6, 2022
A framework that lists all photos in the album that contain faces.

FaceCollectionViewKit A framework that lists all photos in the album that contain faces. Features It uses the detection features of CIDetectorTypeFace

Serhat Akalın 2 Aug 30, 2022
📷 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

junhyi park 1.8k Jan 2, 2023
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
Combine SnapshotTesting images into a single asset

An extension to SnapshotTesting which allows you to create images combining the output of multiple snapshot strategies, assuming they all output to UIImage.

James Sherlock 41 Nov 28, 2022
React-native-photo-editor - Photo editor using native modules for iOS and Android

?? Image editor using native modules for iOS and Android. Inherit from 2 available libraries, ZLImageEditor (iOS) and PhotoEditor (Android)

Baron Ha. 244 Jan 5, 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