Skip to content

Commit

Permalink
add notes about building the UI in code not Storyboards
Browse files Browse the repository at this point in the history
  • Loading branch information
gertig committed Feb 9, 2014
1 parent 2cba7bb commit c6129f3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ source 'https://rubygems.org'
gem 'rake'
# Add your dependencies here:

gem 'awesome_print_motion' # aliased to ap
# gem 'awesome_print_motion' # aliased to ap
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
GEM
remote: https://rubygems.org/
specs:
awesome_print_motion (0.1.0)
rake (10.1.1)

PLATFORMS
ruby

DEPENDENCIES
awesome_print_motion
rake
15 changes: 1 addition & 14 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,7 @@ Motion::Project::App.setup do |app|
app.name = 'AVCam'
app.frameworks += [
'AssetsLibrary',
'AudioToolbox',
'AVFoundation',
'CoreGraphics',
'CoreImage',
'CoreMedia',
'CoreVideo',
'Foundation',
'ImageIO',
'MediaPlayer',
'MessageUI',
'MobileCoreServices',
'OpenGLES',
'QuartzCore',
'SystemConfiguration',
'UIKit'
'SystemConfiguration'
]
end
60 changes: 26 additions & 34 deletions app/AVCamViewController.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,33 +99,40 @@ def self.keyPathsForValuesAffectingSessionRunningAndDeviceAuthorized

def viewDidLoad
super #.viewDidLoad

# Create the AVCaptureSession
session = AVCaptureSession.alloc.init
self.setSession(session)

# Setup the preview view
@previewView = AVCamPreviewView.alloc.initWithFrame(self.view.bounds)

@recordButton = UIButton.buttonWithType(UIButtonTypeCustom)
@recordButton.setTitle("Record", forState:UIControlStateNormal)
@recordButton.addTarget(self, action:"toggleMovieRecording:", forControlEvents:UIControlEventTouchUpInside)
@recordButton.frame = [[32,516], [72, 30]]
# FROM HERE TO...
#########################################################################
self.navigationController.setNavigationBarHidden(true, animated:false)

@previewView = AVCamPreviewView.alloc.initWithFrame(self.view.bounds)

@cameraButton = UIButton.buttonWithType(UIButtonTypeCustom)
@cameraButton.setTitle("Swap", forState:UIControlStateNormal)
@cameraButton.addTarget(self, action:"changeCamera:", forControlEvents:UIControlEventTouchUpInside)
@cameraButton.frame = [[216,516], [72, 30]]
@recordButton = UIButton.buttonWithType(UIButtonTypeCustom)
@recordButton.setTitle("Record", forState:UIControlStateNormal)
@recordButton.addTarget(self, action:"toggleMovieRecording:", forControlEvents:UIControlEventTouchUpInside)
@recordButton.frame = [[32,516], [72, 30]]

@stillButton = UIButton.buttonWithType(UIButtonTypeCustom)
@stillButton.setTitle("Still", forState:UIControlStateNormal)
@stillButton.addTarget(self, action:"snapStillImage:", forControlEvents:UIControlEventTouchUpInside)
@stillButton.frame = [[124,516], [72, 30]]
@cameraButton = UIButton.buttonWithType(UIButtonTypeCustom)
@cameraButton.setTitle("Swap", forState:UIControlStateNormal)
@cameraButton.addTarget(self, action:"changeCamera:", forControlEvents:UIControlEventTouchUpInside)
@cameraButton.frame = [[216,516], [72, 30]]

self.view.addSubview(@previewView)
self.view.addSubview(@recordButton)
self.view.addSubview(@cameraButton)
self.view.addSubview(@stillButton)
@stillButton = UIButton.buttonWithType(UIButtonTypeCustom)
@stillButton.setTitle("Still", forState:UIControlStateNormal)
@stillButton.addTarget(self, action:"snapStillImage:", forControlEvents:UIControlEventTouchUpInside)
@stillButton.frame = [[124,516], [72, 30]]

self.view.addSubview(@previewView)
self.view.addSubview(@recordButton)
self.view.addSubview(@cameraButton)
self.view.addSubview(@stillButton)
#########################################################################
# HERE, IS ADDITIONAL SINCE WE AREN'T USING STORYBOARDS

self.previewView.setSession(session)

Expand Down Expand Up @@ -281,16 +288,10 @@ def willRotateToInterfaceOrientation(toInterfaceOrientation, duration:duration)

def observeValueForKeyPath(keyPath, ofObject:object, change:change, context:context)

NSLog("Observed Value For Key Path: %@", keyPath)
# NSLog("context = %@", context[0])
NSLog("change = %@", change.to_s)

# if context == CapturingStillImageContext
if keyPath == "stillImageOutput.capturingStillImage"
isCapturingStillImage = Utils.boolValue(change[NSKeyValueChangeNewKey])
NSLog("CapturingStillImageContext, change New: %@", isCapturingStillImage.to_s)

# isCapturingStillImage = change["new"].nil?

if isCapturingStillImage
self.runStillImageCaptureAnimation
Expand All @@ -299,8 +300,6 @@ def observeValueForKeyPath(keyPath, ofObject:object, change:change, context:cont
elsif keyPath == "movieFileOutput.recording"
isRecording = Utils.boolValue(change[NSKeyValueChangeNewKey])
NSLog("RecordingContext, change New: %@", isRecording.to_s)

# isRecording = change["new"].nil?

# dispatch_async(dispatch_get_main_queue(), ->{
Dispatch::Queue.main.async {
Expand All @@ -317,11 +316,7 @@ def observeValueForKeyPath(keyPath, ofObject:object, change:change, context:cont
# elsif context == SessionRunningAndDeviceAuthorizedContext
elsif keyPath == "sessionRunningAndDeviceAuthorized"
isRunning = Utils.boolValue(change[NSKeyValueChangeNewKey])
NSLog("SessionRunningAndDeviceAuthorizedContext, change New: %@", isRunning.to_s)
# isRunning = change["new"].nil?


# isRunning = true
NSLog("SessionRunningAndDeviceAuthorizedContext, change New: %@", isRunning.to_s)

# dispatch_async(dispatch_get_main_queue(), ->{
Dispatch::Queue.main.async {
Expand Down Expand Up @@ -366,9 +361,6 @@ def toggleMovieRecording(sender)

# Start recording to a temporary file.
# NSString *outputFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[@"movie" stringByAppendingPathExtension:@"mov"]];

NSLog("FilePath needs work")
# outputFilePath = NSTemporaryDirectory().stringByAppendingPathComponent("movie".stringByAppendingPathExtension("mov"))
outputFilePath = "#{NSTemporaryDirectory()}movie.mov"

self.movieFileOutput.startRecordingToOutputFileURL(NSURL.fileURLWithPath(outputFilePath), recordingDelegate:self)
Expand Down

0 comments on commit c6129f3

Please sign in to comment.