5

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

在此处输入图像描述

4

1 回答 1

2

My guess is that they are using a UICollectionView and checking for the first UICollectionViewCell in collectionView:cellForItemAtIndexPath:. When the UICollectionViewDelegate creates the first cell they have designated a button on that cell which shows a UIImagePickerController when pressed.

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.

E.g.

- (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. 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.

Here is some sample code from Apple that implements a custom camera overlay.

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:

To create a fully-customized image picker for browsing the photo library, use classes from the Assets Library framework. 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. For more information, see Assets Library Framework Reference. Media browsing using the Assets Library framework is available starting in iOS 4.0

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.

Reference:

Fully-Customized Media Capture and Browsing

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

Good Luck! Hopefully this helps!

于 2014-05-01T17:39:01.703 回答