将相机胶卷照片添加到自定义集合视图中 [英] Get Camera Roll photos to a Custom Collection View

查看:120
本文介绍了将相机胶卷照片添加到自定义集合视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带细胞的自定义集合视图。这是我的CollectionView代码。

I have an Custom Collection View with Cells. Here is my CollectionView code.

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
    Cell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"MY_CELL" forIndexPath:indexPath];

    return cell;
}

我想从Camera Roll&显示在这些单元格中。如何在此单元格中查看相机胶卷图像?我应该使用数组来存储图像的名称和放大器吗?然后在Cell中显示它们?
任何人都可以给我一个带代码的解决方案。

I want to get images from Camera Roll & display in these cells. How can I get Camera Roll images to view in this Cell? Should I use an array to store names of the images & then show them in the Cell? Can anyone please give me a solution with a code.

推荐答案

你可以获得专辑和照片/视频资产使用< AssetsLibrary / AssetsLibrary.h> 框架:

You can get the Albums and Photo/video assets using <AssetsLibrary/AssetsLibrary.h> framework :

-(void)getAlbum
{
   library = [[ALAssetsLibrary alloc] init];
ALAssetsLibraryGroupsEnumerationResultsBlock listGroupBlock = ^(ALAssetsGroup *group, BOOL *stop) {

        if (group)
       {
            [_albumsArray addObject:group];
        } else {
            [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
        }
    };

   [library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:listGroupBlock failureBlock:failureBlock]
}

在选择相册时,您将通过以下方式获得照片/视频

While selecting album you will get photos/video by below method

-(void)getAssets
{
    ALAssetsGroupEnumerationResultsBlock assetsEnumerationBlock = ^(ALAsset * result, NSUInteger index, BOOL *stop) {

        if (result)
        {

        }
        else
        {
            [self.tableView reloadData];
        }
    };

    [_assetGroup setAssetsFilter:[ALAssetsFilter allAssets]];

    [_assetGroup enumerateAssetsUsingBlock:assetsEnumerationBlock];
}

请参考此链接了解更多信息和示例与表格视图。您可以用 UICollectionView替换表视图

Please refer this link for more info and example with table view. Alos you can replace table view with your UICollectionView

谢谢!

这篇关于将相机胶卷照片添加到自定义集合视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆