DTPhotosViewController 1.0.4

DTPhotosViewController 1.0.4

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Sep 2016
SPMSupports SPM

Maintained by Dan Jiang.



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+

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)
    }

}