class UnderOs::Image::Picker
A little module to wrap up the built-in iOS images picking/taking
Public Class Methods
new(options={})
click to toggle source
# File lib/under_os/image/picker.rb, line 6 def initialize(options={}) @animated = options.delete(:animated) || true @_ = UIImagePickerController.alloc.init @_.delegate = self end
Public Instance Methods
imagePickerController(picker, didFinishPickingImage:image, editingInfo:info)
click to toggle source
# File lib/under_os/image/picker.rb, line 32 def imagePickerController(picker, didFinishPickingImage:image, editingInfo:info) @page.dismissModalViewControllerAnimated(@animated) @block.call(UnderOs::Image.new(image)) end
pick(&block)
click to toggle source
# File lib/under_os/image/picker.rb, line 21 def pick(&block) @_.setSourceType(UIImagePickerControllerSourceTypePhotoLibrary) start(&block) end
start(&block)
click to toggle source
# File lib/under_os/image/picker.rb, line 26 def start(&block) @block = block @page = UnderOs::App.history.current_page._ @page.presentViewController @_, animated: @animated, completion: nil end
take(&block)
click to toggle source
# File lib/under_os/image/picker.rb, line 12 def take(&block) if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceTypeCamera) @_.setSourceType(UIImagePickerControllerSourceTypeCamera) start(&block) else pick(&block) end end