Ruby motion勉強会 2012年7月

1,902 views

Published on

RBC勉強会資料

Published in: Technology, Education
1 Comment
6 Likes
Statistics
Notes
  • 今日はお忙しい中話をしていただきありがとうございました!
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
1,902
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
26
Comments
1
Likes
6
Embeds 0
No embeds

No notes for slide

Ruby motion勉強会 2012年7月

  1. 1. RubyMotionを使い倒せ 2012年7月20日 Ruby Business Commons Eihiro Saishu
  2. 2. RubyMotionは、iOSのための革新的な製品です。RubyMotionを使えば、iPhoneやiPad向けのネイティブアプリを 素早く開発・テストすることができます。 使うのはみんなが知っていて大好きな 素晴らしいRuby言語だけ。
  3. 3. Ruby Rspec Simulator Native xcode App iPhone icon iOS SDK iPadimage Frameworksound Library etc. etc.
  4. 4. はじめましょう
  5. 5. Objective C to RubyMotion[string drawAtPoint:point withFont:font]; string.drawAtPoint(point, withFont:font)
  6. 6. RubyMotion Syntax
  7. 7. iOS SDKを使う
  8. 8. UIAlertView
  9. 9. 1. UIAlertView object作成2. メッセージ設定3. 表示
  10. 10. UIAlertView23
  11. 11. Although you can use new toinstantiate an Objective-Cclass, I strongly recommendyou use alloc.init or relatedconstructors defined by theclass.
  12. 12. Project
  13. 13. Timerを作る
  14. 14. 時間をセットして カウントダウンゼロになると音楽がなる
  15. 15. UIPickerView "Timer Setting" 時間設定 時間設定 UILabel 終わったら "Count Down Label" 音楽カウントダウン カウントダウン Start Stop UIButton "Start Button"
  16. 16. ベース画面を作る
  17. 17. rake spec
  18. 18. describe "Application MyFirst" do before do @app = UIApplication.sharedApplication end まずこいつ it "has one window" do @app.windows.size.should == 1 endend
  19. 19. @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)@window.rootViewController = MyFirstViewController.alloc.init@window.rootViewController.wantsFullScreenLayout = true@window.makeKeyAndVisible
  20. 20. class MyFirstViewController < UIViewControllerend
  21. 21. Test!
  22. 22. rspec
  23. 23. 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
  24. 24. Label
  25. 25. 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
  26. 26. Button
  27. 27. @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)
  28. 28. def onButton if @timer @timer.invalidate @timer = nil else @timer = NSTimer.scheduledTimerWithTimeInterval(0.1, target:self, selector:timerFired, userInfo:nil, repeats:true) endenddef timerFired @state.text = "%.1f" % (@time -= 0.1) timeExpired if @time <= 0enddef timeExpired @state.text = "Time Up" @timer.invalidate @timer = nil @player.playend
  29. 29. # -*- coding: utf-8 -*-$:.unshift("/Library/RubyMotion/lib")require motion/projectMotion::Project::App.setup do |app| # Use `rake config to see complete project settings. app.name = MyFirst app.frameworks += [AVFoundation, AudioToolbox]end
  30. 30. PickerView
  31. 31. numberOfComponents numberOfRows 選択したData Data data source delegate
  32. 32. @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 = selfview.addSubview(@picker)
  33. 33. # data source for picker viewdef numberOfComponentsInPickerView(pickerView) 1enddef pickerView(pickerView, numberOfRowsInComponent:component) 10enddef pickerView(pickerView, titleForRow:row, forComponent:component) "#{row+1} seconds"end# delegate for picker viewdef pickerView(pickerView, didSelectRow:row, inComponent:component) @time = row + 1 @state.text = @time.to_send
  34. 34. Storyboard
  35. 35. Motion Live
  36. 36. Test Flight
  37. 37. RubyMotion and TestFlight

×