现在网上方便用的swift相册多选几乎没有,于是自己写了一个,用的是PhotoKit,效果图如下
demo github 下载地址
具体看代码就行,写这个相册多选以及图片浏览器有很多细节需要注意的,我也用了不少心血.想了解的看代码.我就说说用法
let album = JDAlbumGroupController()
album.selectImgsClosure1 = { (assets: [PHAsset]) in
for index in 0..<assets.count {
let imgVi = UIImageView()
imgVi.jiuFrame(index: index, column: 3, viW: 100, viH: 100, topMargin: 10)
self.view.addSubview(imgVi)
self.getLitImage(asset: assets[index], callback: { (image) in
imgVi.image = image
})
}
}
let nav = UINavigationController(rootViewController: album)
self.present(nav, animated: true, completion: nil)
typealias ImgCallBackType = (UIImage?)->()
//获取缩略图 缩略图大小需要自己指定
private func getLitImage(asset: PHAsset,callback: @escaping ImgCallBackType){
PHImageManager.default().requestImage(for: asset,
targetSize: CGSize(width: 100, height: 100) , contentMode: .aspectFill,
options: nil, resultHandler: {
(image, _: [AnyHashable : Any]?) in
if image != nil{
callback(image)
}
})
}
//获取原图
private func getOrangeImage(asset: PHAsset,callback: @escaping ImgCallBackType){
//获取原图
PHImageManager.default().requestImage(for: asset,
targetSize: PHImageManagerMaximumSize , contentMode: .aspectFill,
options: nil, resultHandler: {
(image, _: [AnyHashable : Any]?) in
if image != nil{
callback(image)
}
})
}
网友评论