ruby motion勉強会 2012年7月
DESCRIPTION
RBC勉強会資料TRANSCRIPT
![Page 1: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/1.jpg)
RubyMotionを使い倒せ2012年7月20日
Ruby Business CommonsEihiro Saishu
![Page 2: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/2.jpg)
RubyMotionは、iOSのための革新的な製品です。
RubyMotionを使えば、iPhoneやiPad向けのネイティブアプリを素早く開発・テストすることができます。使うのはみんなが知っていて大好きな
素晴らしいRuby言語だけ。
![Page 3: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/3.jpg)
Ruby Rspec
iconimagesoundetc.
iOS SDKFramework
Libraryetc.
xcode
Simulator
iPhoneiPad
NativeApp
![Page 4: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/4.jpg)
![Page 5: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/5.jpg)
![Page 6: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/6.jpg)
![Page 7: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/7.jpg)
はじめましょう
![Page 8: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/8.jpg)
![Page 9: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/9.jpg)
![Page 10: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/10.jpg)
[string drawAtPoint:point withFont:font];string.drawAtPoint(point, withFont:font)
Objective C to RubyMotion
![Page 11: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/11.jpg)
RubyMotion Syntax
![Page 12: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/12.jpg)
iOS SDKを使う
![Page 13: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/13.jpg)
![Page 14: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/14.jpg)
UIAlertView
![Page 15: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/15.jpg)
1. UIAlertView object作成2. メッセージ設定3. 表示
![Page 16: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/16.jpg)
UIAlertView
2
3
![Page 17: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/17.jpg)
![Page 18: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/18.jpg)
![Page 19: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/19.jpg)
Although you can use new to instantiate an Objective-C class, I strongly recommend you use alloc.init or related constructors defined by the class.
![Page 20: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/20.jpg)
![Page 21: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/21.jpg)
Project
![Page 22: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/22.jpg)
Timerを作る
![Page 23: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/23.jpg)
時間をセットしてカウントダウン
ゼロになると音楽がなる
![Page 24: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/24.jpg)
Start
終わったら音楽
時間設定
カウントダウン
Stop
時間設定
カウントダウン
UIPickerView"Timer Setting"
UILabel"Count Down
Label"
UIButton"Start Button"
![Page 25: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/25.jpg)
ベース画面を作る
![Page 26: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/26.jpg)
rake spec
![Page 27: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/27.jpg)
describe "Application 'MyFirst'" do before do @app = UIApplication.sharedApplication end
it "has one window" do @app.windows.size.should == 1 endend
まずこいつ
![Page 28: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/28.jpg)
![Page 29: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/29.jpg)
![Page 30: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/30.jpg)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds) @window.rootViewController = MyFirstViewController.alloc.init @window.rootViewController.wantsFullScreenLayout = true @window.makeKeyAndVisible
![Page 31: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/31.jpg)
![Page 32: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/32.jpg)
class MyFirstViewController < UIViewControllerend
![Page 33: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/33.jpg)
![Page 34: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/34.jpg)
Test!
![Page 35: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/35.jpg)
rspec
![Page 36: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/36.jpg)
describe "Timer Main Window" do
tests MyFirstViewController
it "has one pickerview" do views(UIPickerView).size.should == 1 end it "has Label" do views(UILabel).size.should >= 1 view("Count Down Label").text.should == "Set the Time" end it "has one button" do views(UIButton).size.should == 1 end it "can be time up" do tap("Start Button") view("Count Down Label").text.should == "Time Up" endend
![Page 37: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/37.jpg)
Label
![Page 38: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/38.jpg)
def viewDidLoad @state = UILabel.alloc.init @state.accessibilityLabel = "Count Down Label" @state.font = UIFont.systemFontOfSize(30) @state.text = 'Set the Time' @state.textAlignment = UITextAlignmentCenter @state.textColor = UIColor.whiteColor @state.backgroundColor = UIColor.clearColor @state.frame = [[20, 250], [view.frame.size.width - 20 * 2, 40]] view.addSubview(@state) end
![Page 39: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/39.jpg)
Button
![Page 40: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/40.jpg)
@time = 0
@button = UIButton.buttonWithType(UIButtonTypeRoundedRect) @button.accessibilityLabel = "Start Button" @button.frame = [[40, 310], [view.frame.size.width - 40 * 2, 60]] @button.setTitle("Start", forState:UIControlStateNormal) @button.addTarget(self,
action:"onButton", forControlEvents:UIControlEventTouchDown)
view.addSubview(@button)
url = NSURL.fileURLWithPath(NSBundle.mainBundle.pathForResource("181", ofType: "mp3")) er = Pointer.new(:object) @player = AVAudioPlayer.alloc.initWithContentsOfURL(url, error: er)
![Page 41: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/41.jpg)
def onButton if @timer @timer.invalidate @timer = nil else @timer = NSTimer.scheduledTimerWithTimeInterval(0.1, target:self,
selector:'timerFired', userInfo:nil, repeats:true) end end
def timerFired @state.text = "%.1f" % (@time -= 0.1) timeExpired if @time <= 0 end def timeExpired @state.text = "Time Up" @timer.invalidate @timer = nil @player.play end
![Page 42: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/42.jpg)
# -*- 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 = 'MyFirst' app.frameworks += ['AVFoundation', 'AudioToolbox']end
![Page 43: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/43.jpg)
PickerView
![Page 44: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/44.jpg)
data source
numberOfComponentsnumberOfRows
Data
delegate
選択したData
![Page 45: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/45.jpg)
@picker = UIPickerView.alloc.init @picker.frame = [[20, 20], [view.frame.size.width - 20 * 2, 162]] @picker.accessibilityLabel = "Timer Setting" @picker.showsSelectionIndicator = true @picker.delegate = self @picker.dataSource = self view.addSubview(@picker)
![Page 46: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/46.jpg)
# data source for picker view def numberOfComponentsInPickerView(pickerView) 1 end def pickerView(pickerView, numberOfRowsInComponent:component) 10 end def pickerView(pickerView, titleForRow:row,
forComponent:component) "#{row+1} seconds" end # delegate for picker view def pickerView(pickerView, didSelectRow:row, inComponent:component) @time = row + 1 @state.text = @time.to_s end
![Page 47: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/47.jpg)
Storyboard
![Page 48: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/48.jpg)
Motion Live
![Page 49: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/49.jpg)
Test Flight
![Page 50: Ruby motion勉強会 2012年7月](https://reader036.vdocuments.pub/reader036/viewer/2022062312/5555a96bd8b42afe5d8b46a9/html5/thumbnails/50.jpg)
RubyMotion and TestFlight