SwiftPhotoGallery 3.4.1

SwiftPhotoGallery 3.4.1

测试测试
语言语言 SwiftSwift
许可证 Apache-2.0
发布最后发布2019 年 5 月
SPM支持 SPM

Justin VallelyJustin Vallely 维护。



  • Justin Vallely

SwiftPhotoGallery

Platform Version License CocoaPods tests Swift Dependencies

概述

适用于 iOS 和 tvOS 的全屏照片画廊,使用 Swift 编写。

  • 照片可以滑动和缩放(仅限 iOS)
  • 捏合缩放(仅限 iOS)
  • 双击以最大程度放大,再次双击以最大程度缩小(仅限 iOS)
  • 单击关闭
  • 类似于 Twitter 的滑动关闭(仅限 iOS)
  • 包含可定制的页面指示器
  • 支持任何方向(仅限 iOS)
  • 支持不同尺寸的图像
  • 包含单元测试
  • 几乎可以自定义所有 UI 方面
  • 无缝集成 SDWebImage

用法

要运行示例项目,请克隆仓库,然后从示例目录中运行 pod install

需求

  • iOS 9.0+
  • tvOS 10.0+
  • Xcode 10.2.1+
  • Swift 5.0+

沟通

  • 如果您需要帮助,请使用 Stack Overflow。 (标签 'swiftphotogallery')
  • 如果您想提出一般性问题,请使用 Stack Overflow
  • 如果您发现了一个错误,请打开一个问题。
  • 如果您有功能需求,请打开一个问题。
  • 如果您想贡献,请提交一个拉动请求。

安装

SwiftPhotoGallery 通过 CocoaPods 提供。要安装它,只需在 Podfile 中添加以下行

pod 'SwiftPhotoGallery'

实现

  • 在您的视图控制器中导入框架
import SwiftPhotoGallery
  • 创建一个实例
let gallery = SwiftPhotoGallery(delegate: self, dataSource: self)
  • 自定义外观
gallery.backgroundColor = UIColor.black
gallery.pageIndicatorTintColor = UIColor.gray.withAlphaComponent(0.5)
gallery.currentPageIndicatorTintColor = UIColor.white
gallery.hidePageControl = false
  • 实现数据源
let imageNames = ["image1.jpeg", "image2.jpeg", "image3.jpeg"]

func numberOfImagesInGallery(gallery: SwiftPhotoGallery) -> Int {
    return imageNames.count
}

func imageInGallery(gallery: SwiftPhotoGallery, forIndex: Int) -> UIImage? {
    return UIImage(named: imageNames[forIndex])
}
  • 实现代理
func galleryDidTapToClose(gallery: SwiftPhotoGallery) {
    // do something cool like:
    dismiss(animated: true, completion: nil)
}
  • 展示画廊
present(gallery, animated: true, completion: nil)

完整示例

class ViewController: UIViewController, SwiftPhotoGalleryDataSource, SwiftPhotoGalleryDelegate {

    let imageNames = ["image1.jpeg", "image2.jpeg", "image3.jpeg"]
    var index: Int = 2

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    @IBAction func didPressShowMeButton(sender: AnyObject) {
        let gallery = SwiftPhotoGallery(delegate: self, dataSource: self)

        gallery.backgroundColor = UIColor.black
        gallery.pageIndicatorTintColor = UIColor.gray.withAlphaComponent(0.5)
        gallery.currentPageIndicatorTintColor = UIColor.white
        gallery.hidePageControl = false

        present(gallery, animated: true, completion: nil)

        /*
        /// Or load on a specific page like this:

        present(gallery, animated: true, completion: { () -> Void in
            gallery.currentPage = self.index
        })
        */

    }

    // MARK: SwiftPhotoGalleryDataSource Methods

    func numberOfImagesInGallery(gallery: SwiftPhotoGallery) -> Int {
        return imageNames.count
    }

    func imageInGallery(gallery: SwiftPhotoGallery, forIndex: Int) -> UIImage? {
        return UIImage(named: imageNames[forIndex])
    }

    // MARK: SwiftPhotoGalleryDelegate Methods

    func galleryDidTapToClose(gallery: SwiftPhotoGallery) {
        dismiss(animated: true, completion: nil)
    }
    
}

作者

Justin Vallely,[email protected]

许可

SwiftPhotoGallery可在Apache License 2.0下使用。有关更多信息,请参阅LICENSE文件。