LKAssetsLibraryALAsets图书馆实用程序

联合创作 · 2023-09-27

LKAssetsLibrary 提供 ALAssetsLibrary 分组/过滤/排序 功能。

用法:

LKAssetsLibrary具有3个基本类:

LKAssetsLibrary
LKAassetsGroup
LKasset

这些是ALAssetsLibrary,ALAssetsGroup,ALAsset的包装类。它们具有便捷的方法(例如LKAsset.thumbnail,LKAsset.date等)。

LKAssetsLibrary在获取资产后发布通知。您可以通过观察通知来处理资产。

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(_assetsLibraryDidSetup:)
                                             name:LKAssetsLibraryDidSetupNotification
                                           object:nil];
    self.assetsLibrary = [LKAssetsLibrary assetsLibrary];
    [self.assetsLibrary reload];
}

收到通知后,请使用LKAssetGroup或LKAsset。

- (void)_assetsLibraryDidSetup:(NSNotification*)notification
{
    [self.tableView reloadData];
}

对UITableViewCell使用LKAssetsGroup。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GroupCell" forIndexPath:indexPath];
    
    LKAssetsGroup* assetsGroup = self.assetsLibrary.assetsGroups[indexPath.row];   
    cell.imageView.image = assetsGroup.posterImage;
    cell.textLabel.text = assetsGroup.description;
    return cell;
}

用于UICollectionViewCell。

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    AssetCell* cell = (AssetCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"AssetCell"
                                                                           forIndexPath:indexPath];
    LKAsset* asset = [self.assetsCollection assetForIndexPath:indexPath];
    cell.imageView.image = asset.thumbnail;
    return cell;
}
浏览 3
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报