DTPhotosViewController 1.0.4

DTPhotosViewController 1.0.4

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2016年9月
SPM支持 SPM

Dan Jiang 维护。



介绍

Demo

浏览多张照片。左右滑动查看下一张或上一张。捏合以放大或缩小。单击应该关闭视图控制器。

安装

要求

iOS 8+

使用

导入

import DTPhotosViewController

加载远程照片

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

}

加载本地照片

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

}