A view controller that manages the system interfaces for taking pictures, recording movies, and choosing items from the user's media library.
- iOS 2.0+
An image picker controller manages user interactions and delivers the results of those interactions to a delegate object. The role and appearance of an image picker controller depend on the source type you assign to it before you present it.
To use an image picker controller containing its default controls, perform these steps:
Verify that the device is capable of picking content from the desired source. Do this by calling the
isclass method, providing a constant from the
Source Type Available(_:)
Picker Controller Source Type
Check which media types are available for the source type you’re using, by calling the
availableclass method. This lets you distinguish between a camera that can be used for video recording and one that can be used only for still images.
Tell the image picker controller to adjust the UI according to the media types you want to make available—still images, movies, or both—by setting the
Present the user interface. On iPhone or iPod touch, do this modally (full-screen) by calling the
present(_:method of the currently active view controller, passing your configured image picker controller as the new view controller.
On iPad, the correct way to present an image picker depends on its source type, as summarized in this table:
Saved Photos Album
Use full screen
Must use a popover
Must use a popover
The table indicates that on iPad, if you specify a source type of
saved, you must present the image picker using a popover controller (to learn how to do this, see
UIPopover). If you attempt to present an image picker modally (full-screen) for choosing among saved pictures and movies, the system raises an exception.
On iPad, if you specify a source type of
camera, you can present the image picker modally (full-screen) or by using a popover. However, Apple recommends that you present the camera interface only full-screen.
When the user taps a button to pick a newly-captured or saved image or movie, or cancels the operation, dismiss the image picker using your delegate object. For newly-captured media, your delegate can then save it to the Camera Roll on the device. For previously-saved media, your delegate can then use the image data according to the purpose of your app.
For details on these steps, refer to Taking Pictures and Movies.
You can customize an image picker controller to manage user interactions yourself. To do this, provide an overlay view containing the controls you want to display, and use the methods described in Capturing Still Images or Movies. You can display your custom overlay view in addition to, or instead of, the default controls. Custom overlay views for the
UIImage class are available in iOS 3.1 and later by way of the
camera property. For a code example, see the PhotoPicker: Using UIImagePickerController to Select Pictures and Take Photos sample code project.
Providing a Delegate Object
To use an image picker controller, you must provide a delegate that conforms to the
UIImage protocol. Starting in iOS 4.1, you can use the delegate to save still-image metadata to the Camera Roll along with the image. See
Adjusting Flash Mode
In iOS 4.0 and later, you can provide custom controls to let the user adjust flash mode (on devices that have a flash LED), pick which camera to use (on devices that have a front and rear camera), and switch between still image and movie capture. You can also manage these settings programmatically. You can also manipulate the flash directly to provide effects such as a strobe light. Present a picker interface set to use video capture mode. Then, turn the flash LED on or off by setting the
camera property to
Working with Movies
Movie capture has a default duration limit of 10 minutes but can be adjusted using the
video property. When a user taps the Share button to send a movie to MMS, MobileMe, YouTube, or another destination, an appropriate duration limit and an appropriate video quality are enforced.
The default camera interface supports editing of previously-saved movies. Editing involves trimming from the start or end of the movie, then saving the trimmed movie. To display an interface dedicated to movie editing, rather than one that also supports recording new movies, use the
UIVideo class instead of this one. See
Working with Live Photos
Live Photos is a Camera app feature on supported devices, enabling a picture to be not just a single moment in time but to include motion and sound from the moments just before and after its capture. A
PHLive object represents a Live Photo, and the
PHLive class provides a system-standard, interactive user interface for displaying a Live Photo and playing back its content.
Although Live Photos include sound and motion, they remain photos. When you use an image picker controller to capture or choose still images (by including only the
k type in the
media array), assets that were captured as Live Photos continue to appear in the picker. However, when the user chooses an asset, your
delegate object receives only a
UIImage object containing a still-image representation of the Live Photo.
To obtain the full motion and sound content when the user chooses a Live Photo with the image picker, you must include both the
k types in the
media array. For more information, see
Fully-Customized Media Capture and Browsing
To perform fully-customized image or movie capture, instead use the AV Foundation framework as described in Still and Video Media Capture. Camera access using the AV Foundation framework is available starting in iOS 4.0.
To create a fully-customized image picker for browsing the photo library, use classes from the Photos framework. For example, you could create a custom image picker that displays larger thumbnail images generated and cached by iOS, that makes use of image metadata including timestamp and location information, or that integrates with other features such as MapKit and iCloud Photo Sharing. For more information, see Photos. Media browsing using the Photos framework is available starting in iOS 8.0.