P9PhotoAlbumManager 1.1.1

P9PhotoAlbumManager 1.1.1

Tae Hyun Na 维护。



  • Tae Hyun Na

P9PhotoAlbumManager

一个用于处理 iOS 照片专辑的简单、快速库。

安装

您可以从我们的发布页面下载最新框架文件。P9PhotoAlbumManager 也通过 CocoaPods 提供使用。要安装,只需在 Podfile 中添加以下行。 pod ‘P9PhotoAlbumManager’

播放

首先,您应该检查访问照片专辑的权限,并在需要时请求用户的授权。

if P9PhotoAlbumManager.shared.authorized == false {
    P9PhotoAlbumManager.shared.authorization { (operation, status) in
        if status == .succeed {
            // do something you want.
        }
    }
}

然后,请请求您想要列出的专辑列表。您可以直接使用预定义类型或 PHAssetCollectionType 来描述专辑信息。

let cameraRoll = P9PhotoAlbumManager.AlbumInfo.init(type: .cameraRoll)
let favorite = P9PhotoAlbumManager.AlbumInfo.init(type: .favorite)
let recentlyAdded = P9PhotoAlbumManager.AlbumInfo.init(type: .recentlyAdded)
let screenshots = P9PhotoAlbumManager.AlbumInfo.init(type: .screenshots)
let videos = P9PhotoAlbumManager.AlbumInfo.init(type: .videos, mediaTypes: [.video], ascending: false)
let regular = P9PhotoAlbumManager.AlbumInfo.init(type: .regular)

let albumInfos = [cameraRoll, favorite, recentlyAdded, screenshots, videos, regular]

P9PhotoAlbumManager.shared.requestAlbums(byInfos: albumInfos) { (operation, status) in
    // now, album list cached on P9PhotoAlbumManager.
}

缓存完成后。您可以使用所有信息,并轻松地将它们整合到 UITableView、UICollectionView 等中。

// get count of albums
P9PhotoAlbumManager.shared.numberOfAlbums()
// get album cover image
P9PhotoAlbumManager.shared.imageOfMedia(forIndex: 0, atAlbumIndex: indexPath.row, targetSize: CGSize.init(width: 80, height: 80), contentMode: .aspectFill)

处理专辑中的媒体的方式也相同。

// requesting
P9PhotoAlbumManager.shared.requestMedia(atAlbumIndex: albumIndex) { (operation, status) in
    // now, media list cached on P9PhotoAlbumManager.
}
// get count of medias
P9PhotoAlbumManager.shared.numberOfMediaAtAlbum(forIndex: albumIndex)
// get image of media
P9PhotoAlbumManager.shared.imageOfMedia(forIndex: mediaIndex, atAlbumIndex: albumIndex, targetSize: P9PhotoAlbumManager.maximumImageSize, contentMode: .aspectFill)

您还可以轻松地创建、删除、重命名专辑,以及在专辑中保存和删除媒体(图片、视频、音频)。

许可

适用于适用情况下的 MIT 许可证。http://en.wikipedia.org/wiki/MIT_License