Latest 1.2.2
Homepage https://github.com/tungvoduc/DTPhotoViewerController
License MIT
Platforms ios 8.0
Authors

[![CI Status](http://img.shields.io/travis/Tung Vo/DTPhotoViewerController.svg?style=flat)](https://travis-ci.org/Tung Vo/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

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

pod "DTPhotoViewerController"

Author

Tung Vo, [email protected]

License

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

Latest podspec

{
    "name": "DTPhotoViewerController",
    "version": "1.2.2",
    "summary": "DTPhotoViewerController provides a Facebook-like photo viewer.",
    "platforms": {
        "ios": "8.0"
    },
    "description": "TODO: Add long description of the pod here.nDTPhotoViewerController gives you a Facebook-like photo viewer with similar transition between your view controller and the photo viewer controller. You can create more sophisticated photo viewer by subclassing DTPhotoViewerController.",
    "homepage": "https://github.com/tungvoduc/DTPhotoViewerController",
    "license": "MIT",
    "authors": {
        "Tung Vo": "[email protected]"
    },
    "source": {
        "git": "https://github.com/tungvoduc/DTPhotoViewerController.git",
        "tag": "1.2.2"
    },
    "source_files": "DTPhotoViewerController/Classes/**/*"
}

Pin It on Pinterest

Share This