Sha256: 7983e0b08888ac7ebf1b73227b54fd9668625909580d4fa9a1ad5a057e14d40a
Contents?: true
Size: 1.36 KB
Versions: 20
Compression:
Stored size: 1.36 KB
Contents
class CameraController < UIViewController attr_accessor :buttons def init super.tap do @buttons = [] end end def viewDidLoad super self.view.addSubview(build_button("Library", :any)) self.view.addSubview(build_button("Front", :front)) if BW::Device.camera.front? self.view.addSubview(build_button("Rear", :rear)) if BW::Device.camera.rear? end def build_button(title, camera_method) button = UIButton.buttonWithType(UIButtonTypeRoundedRect) button.setTitle(title, forState:UIControlStateNormal) button.sizeToFit rect = self.buttons.empty? ? CGRectMake(0, 0, 0, 0) : self.buttons.last.frame button.frame = [[rect.origin.x, rect.origin.y + rect.size.height + 10], button.frame.size] button.when UIControlEventTouchUpInside do BW::Device.camera.send(camera_method).picture(media_types: [:image]) do |result| image_view = build_image_view(result[:original_image]) self.view.addSubview(image_view) self.buttons.each { |button| self.view.bringSubviewToFront(button) } end end self.buttons << button button end def build_image_view(image) image_view = UIImageView.alloc.initWithImage(image) image_view.frame = [CGPointZero, self.view.frame.size] image_view.center = [self.view.frame.size.width / 2, self.view.frame.size.height / 2] image_view end end
Version data entries
20 entries across 20 versions & 1 rubygems