测试已测试 | ✓ |
Lang语言 | SwiftSwift |
许可证 | MIT |
发布上次发布 | 2017年12月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Guilherme Munhoz 维护。
CollieGallery 是一个全屏图片库,支持本地和远程图片,它还有许多内置功能,如缩放、平移、交互式过渡等!该库高度可定制,真的很容易让它看起来和工作方式如您所需。
CollieGallery 通过 CocoaPods 提供使用。要安装
它,只需将以下行添加到您的 Podfile 中
pod "CollieGallery"
CollieGallery 真的很容易使用!您只需按照以下步骤操作
导入 CollieGallery 模块
import CollieGallery
创建一个数组来保存图片
var pictures = [CollieGalleryPicture]()
将应在画廊中显示的所有图片添加到数组中。您可以从 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)
使用图片创建一个画廊
let gallery = CollieGallery(pictures: pictures)
在当前视图控制器中显示画廊
gallery.presentInViewController(self)
您也可以通过索引滚动到所需的页面
gallery.scrollToIndex(5)
optional func gallery(gallery: CollieGallery, indexChangedTo index: Int)
可用的定制选项包括
要更改 CollieGallery 的工作方式,您应使用 CollieGalleryOptions 类。您可以通过两种方式更改选项
使用共享的 Options 对象。所有对共享 Options 的更改都将影响所有新实例的画廊。例如,如果您将 enableZoom 属性设置为 false,所有新实例都将禁用图片缩放
CollieGalleryOptions.sharedOptions.enableZoom = false
创建一个新的 CollieGalleryOptions 对象,对其进行自定义,并将其作为 CollieGallery 初始化程序的第二个参数传递
let options = CollieGalleryOptions()
options.enableZoom = false
let gallery = CollieGallery(pictures: pictures, options: options)
可用的外观自定义选项包括
要更改 CollieGallery 的外观,应使用 CollieGalleryAppearance 类。您可以通过两种方式更改相册外观
使用共享外观对象。在共享外观中进行的所有更改将影响所有新的相册实例。例如,如果您将 backgroundColor 属性设置为蓝色,所有新的实例都将有蓝色背景
CollieGalleryAppearance.sharedAppearance.backgroundColor = UIColor.blueColor()
使用 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)
要使用缩放过渡,您需要遵循以下步骤
表明您的视图控制器将实现 CollieGalleryZoomTransitionDelegate
class ViewController: UIViewController, CollieGalleryZoomTransitionDelegate {
实现 CollieGalleryZoomTransitionDelegate
方法
表明可以使用缩放效果关闭图像的边界区域
func zoomTransitionContainerBounds() -> CGRect {
return self.view.frame
}
表明在关闭时图像缩放到的视图
func zoomTransitionViewToDismissForIndex(index: Int) -> UIView?
return self.imageViews[index]
}
显示相册,表明要从哪个视图开始缩放相册并传递视图控制器作为代理
let zoomTransition = CollieGalleryTransitionType.Zoom(fromView: aView, zoomTransitionDelegate: self)
gallery.presentInViewController(self, transitionType: zoomTransition)
要创建自己的操作,请参考以下示例
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)
请参阅CHANGELOG.md
。
Guilherme Munhoz,[email protected]
CollieGallery 可在 MIT 许可证下使用。有关更多信息,请参阅 LICENSE 文件。