一个简单的 PhotoBrowser/Viewer,受 Facebook、Twitter 的图片浏览器启发,使用 swift2.0 编写,基于 IDMPhotoBrowser 和 MWPhotoBrowser。
UIImage
对象或 URL 数组字符串来显示一个或多个图像。将代码直接添加到您的项目中。
请参阅下面的代码片段以了解如何实现示例,或可以容易地理解示例项目。
// add SwipablePhoto Array from UIImage
var images = [SwipablePhoto]()
let photo = SwipablePhoto.photoWithImage(UIImage())// add some UIImage
images.append(photo)
// create PhotoBrowser Instance, and present.
let browser = SwipablePhotoBrowser(photos: images)
browser.initializePageIndex(indexPath.row)
browser.delegate = self
presentViewController(browser, animated: true, completion: {})
从网页 URL
// URL pattern snippet
var images = [SwipablePhoto]()
let photo = SwipablePhoto.photoWithImageURL("https://placehold.jp/150x150.png")
photo.shouldCachePhotoURLImage = false // you can use image cache by true(NSCache)
images.append(photo)
// create PhotoBrowser Instance, and present.
let browser = SwipablePhotoBrowser(photos: images)
browser.initializePageIndex(0)
presentViewController(browser, animated: true, completion: {})
如果您想使用来自现有视图的缩放效果,请使用另一个初始化器
// e.g.: some tableView or collectionView.
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.cellForItemAtIndexPath(indexPath) as! ExampleCollectionViewCell
let originImage = cell.exampleImageView.image! // some image for baseImage
let browser = SwipablePhotoBrowser(originImage: originImage, photos: images, animatedFromView: cell)
browser.initializePageIndex(indexPath.row)
presentViewController(browser, animated: true, completion: {})
}
您可以自定义工具栏按钮(返回/前进,计数器)。
let browser = SwipablePhotoBrowser(originImage: originImage, photos: images, animatedFromView: cell)
browser.displayToolbar = false // all tool bar will be hidden
browser.displayCounterLabel = false // counter label will be hidden
browser.displayBackAndForwardButton = false // back / forward button will be hidden
可以通过在特定的照片上设置 caption
属性,在 PhotoBrowser 的底部简单地显示图片标题
let photo = SwipablePhoto.photoWithImage(UIImage())
photo.caption = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
images.append(photo)
可以启用/禁用垂直滑动
let browser = SwipablePhotoBrowser(originImage: originImage, photos: images, animatedFromView: cell)
browser.disableVerticalSwipe = true
您可以使用属性强制隐藏状态栏
let browser = SwipablePhotoBrowser(originImage: originImage, photos: images, animatedFromView: cell)
browser.isForceStatusBarHidden = true
您可以处理一些由代理触发的触发点。
let browser = SwipablePhotoBrowser(originImage: originImage, photos: images, animatedFromView: cell)
browser.delegate = self
// MARK: - SwipablePhotoBrowserDelegate
func didShowPhotoAtIndex(index: Int) {
// when photo will be shown
}
func willDismissAtPageIndex(index: Int) {
// when PhotoBrowser will be dismissed
}
func didDismissAtPageIndex(index: Int) {
// when PhotoBrowser did dismissed
}
在MIT许可下可用。详细信息请查看LICENSE文件。