简体   繁体   English

ios UIImagePickerController里面的相机滚动?

[英]ios UIImagePickerController inside camera roll?

How can one include the UIImagePickerController inside the camera roll picker similar to what facebook and path do (see screenshot). 如何在相机卷选择器中包含UIImagePickerController,类似于facebook和path所做的(见截图)。 I am just looking to be pointed in the right direction, not specifically looking for code on how to achieve this.. thanks! 我只是想指向正确的方向,而不是专门寻找如何实现这一点的代码..谢谢!

在此输入图像描述

My guess is that they are using a UICollectionView and checking for the first UICollectionViewCell in collectionView:cellForItemAtIndexPath: . 我的猜测是他们正在使用UICollectionView并检查collectionView:cellForItemAtIndexPath:的第一个UICollectionViewCell collectionView:cellForItemAtIndexPath: . When the UICollectionViewDelegate creates the first cell they have designated a button on that cell which shows a UIImagePickerController when pressed. UICollectionViewDelegate创建第一个单元格时,他们在该单元格上指定了一个按钮,按下时会显示UIImagePickerController

Important: 重要:

If you decide to design your own photo browser with an extra cell be sure to +1 in the number of items UICollectionViewDataSource method. 如果您决定使用额外的单元格设计自己的照片浏览器,请确保在项目数量为1的UICollectionViewDataSource方法中。

Eg 例如

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

This is based on the assumption that they have created their own album and are not using the default camera roll. 这是基于他们创建了自己的专辑并且没有使用默认相机胶卷的假设。 Also, I don't use facebook or path so I'm not sure how they are showing that album. 另外,我不使用脸书或路径,所以我不确定他们是如何展示这张专辑的。 Meaning, I don't know if that album is presented when pressing the camera roll button from within the UIImagePickerController or not. 这意味着,我不知道在UIImagePickerController中按下相机胶卷按钮时是否显示该相册。 If so, facebook more than likely has access to private APIs OR they are using their own camera overlay and then displaying their custom album. 如果是这样,Facebook很可能会访问私有API,或者他们使用自己的相机覆盖,然后显示他们的自定义相册。

Here is some sample code from Apple that implements a custom camera overlay. 以下是Apple的一些示例代码,它实现了自定义相机覆盖。

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

EDIT: 编辑:

After further investigation, it looks as if you will have to create your own photo browser to accomplish this. 经过进一步调查后,您似乎必须创建自己的照片浏览器才能完成此操作。 According to the UIImagePickerController Class Reference: 根据UIImagePickerController类参考:

To create a fully-customized image picker for browsing the photo library, use classes from the Assets Library framework. 要创建用于浏览照片库的完全自定义图像选择器,请使用Assets Library框架中的类。 For example, you could create a custom image picker that displays larger thumbnail images, that makes use of EXIF metadata including timestamp and location information, or that integrates with other frameworks such as Map Kit. 例如,您可以创建一个自定义图像选择器,显示更大的缩略图图像,使用EXIF元数据(包括时间戳和位置信息),或者与其他框架(如Map Kit)集成。 For more information, see Assets Library Framework Reference. 有关更多信息,请参阅资产库框架参考。 Media browsing using the Assets Library framework is available starting in iOS 4.0 从iOS 4.0开始,可以使用Assets Library框架进行媒体浏览

So in theory, you could just create you own photo browser using the Asset Library to load the images from the camera roll and insert a button in the first (or whichever) cell that displays a UIImagePickerController, like I mentioned above. 所以理论上,您可以使用资源库创建自己的照片浏览器,从相机胶卷加载图像,并在显示UIImagePickerController的第一个(或任何一个)单元格中插入一个按钮,就像我上面提到的那样。

Reference: 参考:

Fully-Customized Media Capture and Browsing 完全自定义的媒体捕获和浏览

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

Good Luck! 祝好运! Hopefully this helps! 希望这有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM