CollieGallery 0.6.0

CollieGallery 0.6.0

测试已测试
Lang语言 SwiftSwift
许可证 MIT
发布上次发布2017年12月
SwiftSwift 版本3.0
SPM支持 SPM

Guilherme Munhoz 维护。




  • 作者
  • Guilherme Munhoz

CollieGallery

Version
License
Platform

CollieGallery 是一个全屏图片库,支持本地和远程图片,它还有许多内置功能,如缩放、平移、交互式过渡等!该库高度可定制,真的很容易让它看起来和工作方式如您所需。

Interactive Transition
Paging
Zoom

安装

CollieGallery 通过 CocoaPods 提供使用。要安装
它,只需将以下行添加到您的 Podfile 中

pod "CollieGallery"

用法

CollieGallery 真的很容易使用!您只需按照以下步骤操作

  1. 导入 CollieGallery 模块

    import CollieGallery
  2. 创建一个数组来保存图片

    var pictures = [CollieGalleryPicture]()
  3. 将应在画廊中显示的所有图片添加到数组中。您可以从 UIImage 创建图片对象,也可以从一个代表远程图片 URL 的字符串创建

    • 从 UIImage 创建

       let image = UIImage(named: "example")!
       
       let picture = CollieGalleryPicture(image: image)
       pictures.append(picture)
       
       let pictureWithCaption = CollieGalleryPicture(image: image, title: "Collie Picuture", caption: "Picture with caption"))
       pictures.append(pictureWithCaption)
    • 从远程 URL 创建

       let url = "http://example.com/picture.jpg"
       let picture = CollieGalleryPicture(url: url)
       pictures.append(picture)
  4. 使用图片创建一个画廊

    let gallery = CollieGallery(pictures: pictures)
  5. 在当前视图控制器中显示画廊

    gallery.presentInViewController(self)
  6. 您也可以通过索引滚动到所需的页面

    gallery.scrollToIndex(5)

代理函数

  • CollieGalleryDelegate
optional func gallery(gallery: CollieGallery, indexChangedTo index: Int)

定制

选项

可用的定制选项包括

  • parallaxFactor:视差效果的量,从 0 到 1。
  • enableZoom:指示图片是否可以缩放。
  • maximumZoomScale:图片缩放时可以达到的最大比例。
  • showProgress:指示是否显示进度。
  • preLoadedImages:应预加载到当前显示图片旁边图片的数量。
  • gapBetweenPages:每个 scrollview 页面之间的空间。
  • enableSave:指示用户是否可以保存图片。
  • enableInteractiveDismiss:指示用户是否可以通过平移手势交互式地关闭画廊。
  • customActions:将自定义操作显示在操作对话框中的数组和。
  • excludedActions:应不在操作对话框中显示的系统操作数组和。

要更改 CollieGallery 的工作方式,您应使用 CollieGalleryOptions 类。您可以通过两种方式更改选项

  1. 使用共享的 Options 对象。所有对共享 Options 的更改都将影响所有新实例的画廊。例如,如果您将 enableZoom 属性设置为 false,所有新实例都将禁用图片缩放

    CollieGalleryOptions.sharedOptions.enableZoom = false
  2. 创建一个新的 CollieGalleryOptions 对象,对其进行自定义,并将其作为 CollieGallery 初始化程序的第二个参数传递

    let options = CollieGalleryOptions()
    options.enableZoom = false
    
    let gallery = CollieGallery(pictures: pictures, options: options)

外观

可用的外观自定义选项包括

  • backgroundColor:相册的背景颜色。
  • progressBarColor:进度条当前进度的颜色。
  • activityIndicatorColor:活动指示器的颜色。
  • closeButtonColor:关闭按钮图标的颜色。
  • actionButtonColor:操作按钮图标的颜色。

要更改 CollieGallery 的外观,应使用 CollieGalleryAppearance 类。您可以通过两种方式更改相册外观

  1. 使用共享外观对象。在共享外观中进行的所有更改将影响所有新的相册实例。例如,如果您将 backgroundColor 属性设置为蓝色,所有新的实例都将有蓝色背景

    CollieGalleryAppearance.sharedAppearance.backgroundColor = UIColor.blueColor()
  2. 使用 CollieGalleryTheme 类。您可以使用预定义的主题之一或创建自己的主题并将其作为 CollieGallery 初始化器中的第三个参数传递

    • 预定义主题

       let gallery = CollieGallery(pictures: pictures, options: nil, theme: CollieGalleryTheme.Dark)
    • 自定义主题

       let appearance = CollieGalleryAppearance()
       appearance.backgroundColor = UIColor.blueColor()
       
       let theme = CollieGalleryTheme(appearance: appearance)
       
       let gallery = CollieGallery(pictures: pictures, options: nil, theme: theme)

过渡效果

要更改用于显示和关闭相册的过渡效果,应使用 CollieGalleryTransitionType 类。您可以将可用的过渡类型之一作为 presentInViewController 函数的第二个参数传递

gallery.presentInViewController(self, CollieGalleryTransitionType.Default)

缩放过渡

Interactive Transition

要使用缩放过渡,您需要遵循以下步骤

  1. 表明您的视图控制器将实现 CollieGalleryZoomTransitionDelegate

    class ViewController: UIViewController, CollieGalleryZoomTransitionDelegate {
  2. 实现 CollieGalleryZoomTransitionDelegate 方法

    • 表明可以使用缩放效果关闭图像的边界区域

       func zoomTransitionContainerBounds() -> CGRect {
       	return self.view.frame
       }
    • 表明在关闭时图像缩放到的视图

       func zoomTransitionViewToDismissForIndex(index: Int) -> UIView?
       	return self.imageViews[index]
       }
  3. 显示相册,表明要从哪个视图开始缩放相册并传递视图控制器作为代理

    let zoomTransition = CollieGalleryTransitionType.Zoom(fromView: aView, zoomTransitionDelegate: self)
    gallery.presentInViewController(self, transitionType: zoomTransition)

自定义操作

Custom Action

要创建自己的操作,请参考以下示例

let options = CollieGalleryOptions()

let customAction = CollieGalleryCustomAction(title: "Custom Action", imageName: "imageName") { () -> () in
    print("Custom Action Tapped!")
}

options.customActions = [customAction]

let gallery = CollieGallery(pictures: pictures, options: options)

排除操作

要从对话框中删除默认操作,请参考以下示例

let options = CollieGalleryOptions()
        
let customAction = CollieGalleryCustomAction(title: "Custom Action", imageName: "settings") { () -> () in
    print("Custom Action Tapped!")
}

options.excludedActions = [UIActivityTypeAssignToContact, UIActivityTypeCopyToPasteboard, UIActivityTypePrint]

let gallery = CollieGallery(pictures: pictures, options: options)

要求

  • iOS 8.0

更新日志

请参阅CHANGELOG.md

作者

Guilherme Munhoz,[email protected]

许可证

CollieGallery 可在 MIT 许可证下使用。有关更多信息,请参阅 LICENSE 文件。