Ruby motion勉強会 2012年7月
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Ruby motion勉強会 2012年7月

  • 2,028 views
Uploaded on

RBC勉強会資料

RBC勉強会資料

More in: Technology , Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
2,028
On Slideshare
2,028
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
24
Comments
1
Likes
6

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. RubyMotionを使い倒せ 2012年7月20日 Ruby Business Commons Eihiro Saishu
  • 2. RubyMotionは、iOSのための革新的な製品です。RubyMotionを使えば、iPhoneやiPad向けのネイティブアプリを 素早く開発・テストすることができます。 使うのはみんなが知っていて大好きな 素晴らしいRuby言語だけ。
  • 3. Ruby Rspec Simulator Native xcode App iPhone icon iOS SDK iPadimage Frameworksound Library etc. etc.
  • 4. はじめましょう
  • 5. Objective C to RubyMotion[string drawAtPoint:point withFont:font]; string.drawAtPoint(point, withFont:font)
  • 6. RubyMotion Syntax
  • 7. iOS SDKを使う
  • 8. UIAlertView
  • 9. 1. UIAlertView object作成2. メッセージ設定3. 表示
  • 10. UIAlertView23
  • 11. Although you can use new toinstantiate an Objective-Cclass, I strongly recommendyou use alloc.init or relatedconstructors defined by theclass.
  • 12. Project
  • 13. Timerを作る
  • 14. 時間をセットして カウントダウンゼロになると音楽がなる
  • 15. UIPickerView "Timer Setting" 時間設定 時間設定 UILabel 終わったら "Count Down Label" 音楽カウントダウン カウントダウン Start Stop UIButton "Start Button"
  • 16. ベース画面を作る
  • 17. rake spec
  • 18. describe "Application MyFirst" do before do @app = UIApplication.sharedApplication end まずこいつ it "has one window" do @app.windows.size.should == 1 endend
  • 19. @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)@window.rootViewController = MyFirstViewController.alloc.init@window.rootViewController.wantsFullScreenLayout = true@window.makeKeyAndVisible
  • 20. class MyFirstViewController < UIViewControllerend
  • 21. Test!
  • 22. rspec
  • 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. Label
  • 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. Button
  • 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. 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. # -*- 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. PickerView
  • 31. numberOfComponents numberOfRows 選択したData Data data source delegate
  • 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. # 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. Storyboard
  • 35. Motion Live
  • 36. Test Flight
  • 37. RubyMotion and TestFlight