Created
April 27, 2016 15:22
-
-
Save perlmunger/a443d737b192b2e19606df70a9206338 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
// ImagePicker encapsulates UIImagePickerViewController functioality providing a convenient | |
// closure interface for responding to user interactions | |
import UIKit | |
import MobileCoreServices | |
class ImagePicker : NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate { | |
var didFinishPickingMediaWithInfo:((info:[String:AnyObject]) -> ())? | |
var didCancelPickingMedia:(() -> ())? | |
let imagePicker = UIImagePickerController() | |
override init() { | |
super.init() | |
// Set some defaults. These can be overriden by access the | |
// imagePicker member variable. | |
imagePicker.sourceType = .Camera | |
imagePicker.showsCameraControls = true | |
imagePicker.allowsEditing = true | |
imagePicker.mediaTypes = [kUTTypeImage as String] | |
imagePicker.delegate = self | |
} | |
func presentFromViewController(viewController:UIViewController) { | |
viewController.presentViewController(imagePicker, animated: true, completion: nil) | |
} | |
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { | |
self.didFinishPickingMediaWithInfo?(info: info) | |
} | |
func imagePickerControllerDidCancel(picker: UIImagePickerController) { | |
self.didCancelPickingMedia?() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment