Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add Camera Sample #27

Closed
wants to merge 1 commit into from

2 participants

@tanukiti1987

Add camera sample with UIImagePickerController.

It's just take picture and save photo library.

IMG_0770

@alloy alloy closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 31, 2013
  1. @tanukiti1987
This page is out of date. Refresh to see the latest.
View
3  Camera/README
@@ -0,0 +1,3 @@
+Camera.app
+
+This sample demonstrates the following concepts: UIImagePickerController.
View
9 Camera/Rakefile
@@ -0,0 +1,9 @@
+# coding: utf-8
+$:.unshift("/Library/RubyMotion/lib")
+require 'motion/project'
+
+Motion::Project::App.setup do |app|
+ # Use `rake config' to see complete project settings.
+ app.name = 'Camera'
+ app.info_plist['UIStatusBarHidden'] = true
+end
View
9 Camera/app/app_delegate.rb
@@ -0,0 +1,9 @@
+class AppDelegate
+ def application(application, didFinishLaunchingWithOptions:launchOptions)
+ @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.applicationFrame)
+ @window.rootViewController = CameraViewController.alloc.init
+ @window.rootViewController.wantsFullScreenLayout = true
+ @window.makeKeyAndVisible
+ true
+ end
+end
View
58 Camera/app/camera_view_controller.rb
@@ -0,0 +1,58 @@
+class CameraViewController < UIViewController
+ INVALID_LABEL_WIDTH = 260
+ INVALID_LABEL_HEIGHT = 40
+ INVALID_LABEL_POS_X = (UIScreen.mainScreen.bounds.size.width - INVALID_LABEL_WIDTH) / 2
+ INVALID_LABEL_POS_Y = (UIScreen.mainScreen.bounds.size.height - INVALID_LABEL_HEIGHT) / 2
+
+ FIRE_BUTTON_MARGIN = 5
+ FIRE_BUTTON_WIDTH = 320
+ FIRE_BUTTON_HEIGHT = 44
+ FIRE_BUTTON_POS_X = 0
+ FIRE_BUTTON_POS_Y = UIScreen.mainScreen.bounds.size.height - FIRE_BUTTON_HEIGHT - FIRE_BUTTON_MARGIN
+
+ def viewDidLoad
+ self.view.backgroundColor = UIColor.blackColor
+ end
+
+ def viewDidAppear(animated)
+ if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceTypeCamera)
+ @ipc = UIImagePickerController.alloc.init
+ @ipc.delegate = self
+ @ipc.sourceType = UIImagePickerControllerSourceTypeCamera
+ @ipc.allowsEditing = false
+ @ipc.showsCameraControls = false
+ @ipc.view.addSubview(fire_button)
+ self.presentModalViewController(@ipc, animated: true)
+ else
+ make_invalid_screen
+ end
+ end
+
+ def make_invalid_screen
+ invalid_label = UILabel.new.tap do |label|
+ label.text = 'The device can not use camera'
+ label.textColor = UIColor.whiteColor
+ label.backgroundColor = UIColor.blackColor
+ label.frame = [[INVALID_LABEL_POS_X, INVALID_LABEL_POS_Y],
+ [INVALID_LABEL_WIDTH, INVALID_LABEL_HEIGHT]]
+ end
+ self.view.addSubview(invalid_label)
+ end
+
+ def fire_button
+ button = UIButton.buttonWithType(UIButtonTypeRoundedRect)
+ button.setTitle("Take picture", forState: UIControlStateNormal)
+ button.frame = [[FIRE_BUTTON_POS_X, FIRE_BUTTON_POS_Y],
+ [FIRE_BUTTON_WIDTH, FIRE_BUTTON_HEIGHT]]
+ button.addTarget(self, action:'take_picture', forControlEvents:UIControlEventTouchUpInside)
+ end
+
+ def take_picture
+ @ipc.takePicture
+ end
+
+ def imagePickerController(picker, didFinishPickingMediaWithInfo:info)
+ imageToSave = info.objectForKey UIImagePickerControllerOriginalImage
+ UIImageWriteToSavedPhotosAlbum(imageToSave, nil, nil, nil)
+ end
+end
View
BIN  Camera/resources/Default-568h@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Something went wrong with that request. Please try again.