Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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). I am just looking to be pointed in the right direction, not specifically looking for code on how to achieve this.. thanks!

enter image description here

like image 588
sudo Avatar asked Nov 01 '22 00:11

sudo


1 Answers

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!

like image 87
Jonathan Avatar answered Nov 12 '22 17:11

Jonathan