【问题标题】:ios UIImagePickerController inside camera roll?ios UIImagePickerController 在相机胶卷内?
【发布时间】:2014-05-01 17:06:52
【问题描述】:

如何将 UIImagePickerController 包含在相机胶卷选取器中,类似于 facebook 和 path 所做的(见截图)。我只是想指出正确的方向,而不是专门寻找有关如何实现这一目标的代码..谢谢!

【问题讨论】:

    标签: ios uiimagepickercontroller camera-roll


    【解决方案1】:

    我的猜测是他们正在使用UICollectionView 并检查collectionView:cellForItemAtIndexPath: 中的第一个UICollectionViewCell。当UICollectionViewDelegate 创建第一个单元格时,他们在该单元格上指定了一个按钮,按下时会显示UIImagePickerController

    重要:

    如果您决定设计自己的带有额外单元格的照片浏览器,请确保在 UICollectionViewDataSource 方法中的项目数量 +1。

    例如

    - (void)showImagePicker:(id)sender
    {
        // Present the UIImagePickerController
    }
    
    - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
    {
        return [self.photos count] + 1;
    }    
    
    - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        if (indexPath.row == 0)
        {
            // You could also just as easily add a button to a UICollectionViewCell
            // Instead of creating a custom subclass.
            CameraButtonCell * cell = ...;
            [cell.button addTarget:self action:@selector(showImagePicker:) forControlEvents:UIControlEventTouchUpInside];
    
            return cell;
        }
    
        UICollectionViewCell * cell = ...;
    
        return cell;
    }
    

    这是基于他们创建了自己的相册并且没有使用默认相机胶卷的假设。另外,我不使用 facebook 或路径,所以我不确定他们是如何展示这张专辑的。意思是,我不知道从 UIImagePickerController 中按下相机胶卷按钮时是否显示该专辑。如果是这样,facebook 很可能可以访问私有 API,或者他们正在使用自己的相机叠加层,然后显示他们的自定义相册。

    这是来自 Apple 的一些示例代码,用于实现自定义相机叠加层。

    https://developer.apple.com/library/ios/samplecode/PhotoPicker/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010196

    编辑:

    经过进一步调查,您似乎必须创建自己的照片浏览器才能完成此操作。根据 UIImagePickerController 类参考:

    创建一个完全自定义的图像选择器来浏览照片 库,使用资产库框架中的类。例如, 您可以创建一个显示更大缩略图的自定义图像选择器 图像,利用 EXIF 元数据,包括时间戳和 位置信息,或与其他框架集成,例如 地图套件。有关详细信息,请参阅资产库框架参考。 可以使用资产库框架进行媒体浏览 从 iOS 4.0 开始

    所以理论上,您可以创建自己的照片浏览器,使用资源库从相机胶卷中加载图像,并在显示 UIImagePickerController 的第一个(或任何一个)单元格中插入一个按钮,就像我上面提到的那样。

    参考:

    完全自定义的媒体捕获和浏览

    https://developer.apple.com/library/ios/documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html

    祝你好运!希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-05
      • 1970-01-01
      • 2018-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多