9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Storyboardを使ってRubyMotionで開発する方法

Posted at

RubyMotionでもStoryBoardが使えるらしいので,試してみた.

ひな形作成

$ motion create SB
$ cd SB

XcodeでStoryboardを作成

おもむろにXCodeを開きます.

File>New>FileiOS>User Interface>Storyboardを選びます.

初めに表示されるViewControllerを作成

UIViewController設置.

IdentifierをFirstとか付けます.

UILabelとUIButtonを追加します.

Segueで遷移する先のViewControllerを作成

もう一つUIViewController設置.

IdentifierをSecondとか付けときます.

Segueの設定

Firstに配置したButtonを,Ctrlを押しながら引っ張ってSecondのViewControllerへ繋ぎます.
Storyboard Seguesの設定が出るので,Modalとかを選ぶ.

Storyboardの保存

Cmd+sでStoryboardをresources/Storyboard.storyboardとか名前を付けて保存します.

storyboardのコンパイル

$ ibtool --compile resources/Storyboard.storyboardc resources/Storyboard.storyboard

コーディング

app/app_delegate.rbを書く.
Storyboardからロードします.

class AppDelegate
  def application(application, didFinishLaunchingWithOptions:launchOptions)
    @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
    @sb = UIStoryboard.storyboardWithName('Storyboard', bundle: nil)
    rvc = @sb.instantiateViewControllerWithIdentifier("First")
    @window.rootViewController = rvc
    @window.rootViewController.wantsFullScreenLayout = true
    @window.makeKeyAndVisible
    true
  end
end

ちなみに,Buttonの動作を変えたい場合などは,Firstと付けたUIViewControllerをCustom Classに変更してUIViewControllerを継承したクラスを作成して,prepareForSegue:sender:で遷移前に処理を行うとか,UIButtonのaddTarget:senderとかにselectorを登録して処理を行うとかします.

コンパイルして実行

  $rake

とすれば,Simulatorが立ち上がります.
設置したButtonを押せばSecondのViewへ切り替わります.

9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?