ݺߣ

ݺߣShare a Scribd company logo
ܲѴdzپDzԤʹ
      2012720
   Ruby Business Commons
        Eihiro Saishu
RubyMotionϡiOSΤθµĤuƷǤ

RubyMotionʹСiPhoneiPad򤱤Υͥƥ֥ץ
      礯_k?ƥȤ뤳ȤǤޤ
       ʹΤϤߤʤ֪äƤƴä

          餷RubyZ
Ruby     Rspec

                                     Simulator


                    Native
                             xcode
                     App

                                      iPhone
 icon    iOS SDK                        iPad
image   Framework
sound     Library
 etc.       etc.
Ruby motion㏊ 20127
Ruby motion㏊ 20127
Ruby motion㏊ 20127
Ϥޤ礦
Ruby motion㏊ 20127
Ruby motion㏊ 20127
Objective C to RubyMotion



[string drawAtPoint:point withFont:font];
 string.drawAtPoint(point, withFont:font)
RubyMotion Syntax
iOS SDKʹ
Ruby motion㏊ 20127
UIAlertView
1. UIAlertView object
2. å`O
3. ʾ
UIAlertView




2




3
Ruby motion㏊ 20127
Ruby motion㏊ 20127
Although you can use new to
instantiate an Objective-C
class, I strongly recommend
you use alloc.init or related
constructors de?ned by the
class.
Ruby motion㏊ 20127
Project
վ
rg򥻥åȤ
 ȥ
ˤʤSʤ
UIPickerView
         "Timer Setting"




 rgO                       rgO
              UILabel
                                     Kä
            "Count Down
               Label"                 S



ȥ                    ȥ


 Start                       Stop

            UIButton
         "Start Button"
٩`
rake spec
describe "Application 'MyFirst'" do
 before do
   @app = UIApplication.sharedApplication
 end
                                    ޤ
 it "has one window" do
   @app.windows.size.should == 1
 end
end
Ruby motion㏊ 20127
Ruby motion㏊ 20127
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
@window.rootViewController = MyFirstViewController.alloc.init
@window.rootViewController.wantsFullScreenLayout = true
@window.makeKeyAndVisible
Ruby motion㏊ 20127
class MyFirstViewController < UIViewController
end
Ruby motion㏊ 20127
Test!
rspec
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"
 end
end
Label
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
Button
@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.?leURLWithPath(NSBundle.mainBundle.pathForResource("181", ofType:
"mp3"))
   er = Pointer.new(:object)
   @player = AVAudioPlayer.alloc.initWithContentsOfURL(url, error: er)
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
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'

Motion::Project::App.setup do |app|
 # Use `rake con?g' to see complete project settings.
 app.name = 'MyFirst'
 app.frameworks += ['AVFoundation', 'AudioToolbox']
end
PickerView
numberOfComponents
   numberOfRows      xkData
       Data


    data source       delegate
@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)
# 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
Storyboard
Motion Live
Test Flight
RubyMotion and
   TestFlight

More Related Content

Ruby motion㏊ 20127

  • 1. ܲѴdzپDzԤʹ 2012720 Ruby Business Commons Eihiro Saishu
  • 2. RubyMotionϡiOSΤθµĤuƷǤ RubyMotionʹСiPhoneiPad򤱤Υͥƥ֥ץ 礯_k?ƥȤ뤳ȤǤޤ ʹΤϤߤʤ֪äƤƴä 餷RubyZ
  • 3. Ruby Rspec Simulator Native xcode App iPhone icon iOS SDK iPad image Framework sound Library etc. etc.
  • 10. Objective C to RubyMotion [string drawAtPoint:point withFont:font]; string.drawAtPoint(point, withFont:font)
  • 19. Although you can use new to instantiate an Objective-C class, I strongly recommend you use alloc.init or related constructors de?ned by the class.
  • 22. վ
  • 24. UIPickerView "Timer Setting" rgO rgO UILabel Kä "Count Down Label" S ȥ ȥ Start Stop UIButton "Start Button"
  • 25. ٩`
  • 27. describe "Application 'MyFirst'" do before do @app = UIApplication.sharedApplication end ޤ it "has one window" do @app.windows.size.should == 1 end end
  • 30. @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds) @window.rootViewController = MyFirstViewController.alloc.init @window.rootViewController.wantsFullScreenLayout = true @window.makeKeyAndVisible
  • 32. class MyFirstViewController < UIViewController end
  • 34. Test!
  • 35. rspec
  • 36. 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" end end
  • 37. Label
  • 38. 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
  • 40. @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.?leURLWithPath(NSBundle.mainBundle.pathForResource("181", ofType: "mp3")) er = Pointer.new(:object) @player = AVAudioPlayer.alloc.initWithContentsOfURL(url, error: er)
  • 41. 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
  • 42. # -*- coding: utf-8 -*- $:.unshift("/Library/RubyMotion/lib") require 'motion/project' Motion::Project::App.setup do |app| # Use `rake con?g' to see complete project settings. app.name = 'MyFirst' app.frameworks += ['AVFoundation', 'AudioToolbox'] end
  • 44. numberOfComponents numberOfRows xkData Data data source delegate
  • 45. @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)
  • 46. # 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
  • 50. RubyMotion and TestFlight