ios - 将相机胶卷照片获取到自定义收藏 View

标签 ios iphone objective-c uicollectionview uiimagepickercontroller

我有一个带有单元格的自定义 Collection View 。这是我的 CollectionView 代码。

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

    return cell;
}

我想从相机胶卷中获取图像并显示在这些单元格中。我怎样才能在这个单元格中查看相机胶卷图像?我应该使用数组来存储图像的名称然后在 Cell 中显示它们吗? 谁能给我一个带有代码的解决方案。

最佳答案

您可以使用 <AssetsLibrary/AssetsLibrary.h> 获取相册和照片/视频资源框架:

-(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]
}

选择相册时,您将通过以下方法获取照片/视频

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

        if (result)
        {

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

    [_assetGroup setAssetsFilter:[ALAssetsFilter allAssets]];

    [_assetGroup enumerateAssetsUsingBlock:assetsEnumerationBlock];
}

请引用这个link有关 TableView 的更多信息和示例。另外,您可以用 UICollectionView 替换表格 View

谢谢!

关于ios - 将相机胶卷照片获取到自定义收藏 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22575568/

相关文章:

iphone - 在 UIView 中加载不同的 View Controller (就像 Xcode 的 iFrame)

ios - 如何对齐 View 和 subview 中心 Objective-C

objective-c - 当方法可以返回子类时,返回类型应该是什么?

android - iOS 到 Android 的 Json-RPC 方法

ios - AVAudioPlayer 'forgets' 由 MPRemoteCommand 触发时播放

ios - 如何使用 swift 将字符串分成字节组

iphone - 邮件撰写 View Controller 导航栏

ios - 在 iPad 上共享工作表崩溃

ios - 使用 CAGradientLayer 定义渐变的角度

ios - iOS LinkedIn SDK 没有回调