Tag Archives: UIImagePickerController

How to display Live Photos in a view controller

Live Photo

Live Photos are a brand new kettle of fish: they’re not a UIImage (nor an NSImage), and they’re not a video resource either. To make use of them, Apple gave us a few new classes in iOS 9: PHLivePhoto and PHLivePhotoView. In addition there’s the the PHLivePhotoViewDelegate protocol we can utilise.

Let’s see how to grab a Live Photo from the user’s camera roll, check if it is in fact a Live Photo, and then display it in a Live Photo View. I’ll also describe how to animate the image programmatically.

Continue reading

How to use Popovers on iPad – Part 3: Image Picker

In this series I’ll show you how to create Popovers on iPad. They’re fairly easy to create once you get the hang of the inner workings of the UIPopoverController.

I’ll show you how to create basic Popover in code and in your Storyboard, and we’ll discuss how you can retrieve data from a Popover when it’s dismissed. We’ll do this with a simple UIDatePicker. In the last video I’ll demonstrate how you can pick images from the camera roll using the UImagePickerController with a Popover – which is how you’re meant to do it on iPad.

The series contains three videos in total:

  • Part 1 deals with the initial code and class etup
  • Part 2 deals with setting up the UIStoryboard and connect our code to it
  • and in Part 3 we’ll implement a UIImagePickerController to demonstrate a use case

Enjoy!

Get the code for this project on GitHub

Watch the full course in one convenient playlist:
Catch this episode on my iOS Dev Diary Podcast:

How to use Popovers on iPad – Part 1: Code

In this series I’ll show you how to create Popovers on iPad. They’re fairly easy to create once you get the hang of the inner workings of the UIPopoverController.

I’ll show you how to create basic Popover in code and in your Storyboard, and we’ll discuss how you can retrieve data from a Popover when it’s dismissed. We’ll do this with a simple UIDatePicker. In the last video I’ll demonstrate how you can pick images from the camera roll using the UImagePickerController with a Popover – which is how you’re meant to do it on iPad.

The series contains three videos in total:

  • Part 1 deals with the initial code and class etup
  • Part 2 deals with setting up the UIStoryboard and connect our code to it
  • and in Part 3 we’ll implement a UIImagePickerController to demonstrate a use case

Enjoy!

Get the code for this project on GitHub

Watch the full course in one convenient playlist:
Catch this episode on my iOS Dev Diary Podcast:

How to record video files in your iOS App

Recording video is very similar to taking a picture with the built-in device camera: we can use the UIImagePickerController – all we do is to specify the video camera for picking actions.

Here’s how can create it:

Note the very first line for importing the Mobile Core Services framework – it needs to be imported and linked to in your project. This is not mentioned anywhere in the official Apple Documentation at the time of writing! We need this to specify the media types array for the image picker. With it we’re saying “only allow movies”. Without the framework Xcode won’t know what kUTTypeMovie is.

If the device doesn’t have a camera this method would crash (Simulator for example, or iPhone 3G), hence the if/then statement.

When the picker is finished you can access the movie URLs in its delegate method which we need to conform, just as we do with picking pictures:

Here we create a new URL in our Documents directory (via the grabFileURL method), turn movie URL into data, and use an NSData method to save our video data into our own URL. In addition and for demonstration we’re also saving our video to the Camera Roll.

The last line dismisses the picker. We do the same when the user hits cancel.

There’s a quick and dirty Demo Project on GitHub to illustrate all this.

How to select a UIImage from the camera roll (and use it)

The UIImagePickerController can help us do this with ease.

In this example we’ll instantiate an image picker and tell it what kind of image we want returned. We have a choice of using an edited version, use the original, or start using a camera. Next we present the picker from which the user can select the image:

This content is for members only.