Latest 1.0.4
Homepage https://github.com/danjiang/DTPhotosViewController
License MIT
Platforms ios 8.0, requires ARC
Authors

Introduction

Demo

Browse multiple photos. Swipe left or right to see next or previous. Pinch to zoom in or out. Single tap should dismiss view controller.

Installation

Requirement

iOS 8+

CocoaPods

To install DTPhotosViewController add a dependency to your Podfile:

# source 'https://github.com/CocoaPods/Specs.git'
# use_frameworks!
# platform :ios, "8.0"

pod "DTPhotosViewController"

Carthage

To install DTPhotosViewController add a dependency to your Cartfile:

github "danjiang/DTPhotosViewController"

Usage

Import

import DTPhotosViewController

Load Remote Photos

class ViewController: UIViewController {

    private let remoteImages = [NSURL(string: "/images/apple-keynote-20120912.jpg")!,
                                NSURL(string: "/images/apple-keynote-20140909.jpg")!,
                                NSURL(string: "/images/apple-keynote-20150909.jpg")!]
    private let placeholderImage = UIImage(named: "placeholder_large")

    @IBAction func manyRemotePhotos(sender: AnyObject) {
        let photoURLs = remoteImages

        let photosViewController = DTPhotosViewController(photoURLs: photoURLs, placeholderImage: placeholderImage, currentPage: 1)
        photosViewController.handler = self
        presentViewController(photosViewController, animated: true, completion: nil)
    }

}

// MARK - DTPhotosViewControllerPhotosURLHandler
extension ViewController: DTPhotosViewControllerPhotosURLHandler {

    func photosViewController(photosViewController: DTPhotosViewController, photoURL: NSURL, viewController: UIViewController) {
        let networking = Networking(baseURL: "http://blog.danthought.com")
        networking.downloadImage(photoURL.absoluteString) { image, error in
            if let image = image {
                dispatch_async(dispatch_get_main_queue(), {
                    photosViewController.setPhotoImage(image, forViewController: viewController)
                })
            } else {
                print(error)
            }
        }
    }

}

Load Local Photos

class ViewController: UIViewController {

    private let localImages = [UIImage(named: "apple-keynote-20130910")!,
                               UIImage(named: "apple-keynote-20140602")!,
                               UIImage(named: "apple-keynote-20150309")!]
    private let placeholderImage = UIImage(named: "placeholder_large")

    @IBAction func manyLocalPhotos(sender: AnyObject) {
        let photoImages = localImages

        let photosViewController = DTPhotosViewController(photoImages: photoImages, placeholderImage: placeholderImage, currentPage: 1)
        presentViewController(photosViewController, animated: true, completion: nil)
    }

}

Latest podspec

{
    "name": "DTPhotosViewController",
    "version": "1.0.4",
    "summary": "Browse multiple photos. Swipe left or right to see next or previous. Pinch to zoom in or out. Single tap should dismiss view controller.",
    "homepage": "https://github.com/danjiang/DTPhotosViewController",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Dan Jiang": "[email protected]"
    },
    "social_media_url": "http://twitter.com/dtstudio",
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source": {
        "git": "https://github.com/danjiang/DTPhotosViewController.git",
        "tag": "1.0.4",
        "submodules": true
    },
    "source_files": "Sources/**/*.{h,swift}"
}

Pin It on Pinterest

Share This