Skip to content

Instantly share code, notes, and snippets.

@jpmartha
Created December 10, 2015 09:58
Show Gist options
  • Save jpmartha/1808d573dae73ae20dcf to your computer and use it in GitHub Desktop.
Save jpmartha/1808d573dae73ae20dcf to your computer and use it in GitHub Desktop.
import UIKit
import Photos
import PhotosUI
import MobileCoreServices
class LivePhotosViewController: UIViewController,
PHLivePhotoViewDelegate,
UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var livePhotosView: PHLivePhotoView!
let imagePicker = UIImagePickerController()
override func viewDidLoad() {
super.viewDidLoad()
livePhotosView.contentMode = .ScaleAspectFill
livePhotosView.delegate = self
}
@IBAction func showButtonTapped(sender: UIBarButtonItem) {
showImagePicker()
}
func showImagePicker() {
imagePicker.delegate = self
imagePicker.sourceType = .PhotoLibrary
imagePicker.mediaTypes = [kUTTypeImage as String, kUTTypeLivePhoto as String]
presentViewController(imagePicker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
dismissViewControllerAnimated(true, completion: nil)
if let livePhoto = info[UIImagePickerControllerLivePhoto] as? PHLivePhoto {
livePhotosView.livePhoto = livePhoto
livePhotosView.startPlaybackWithStyle(.Full)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment