Created
December 10, 2015 09:58
-
-
Save jpmartha/1808d573dae73ae20dcf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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