Gems

Gems 是可以在项目中重复使用的第三方组件。RubyMotion 社区已经开发出数量众多的 Gem。这里是其中部分 Gem,访问 Motion Toolbox,获知更多的 Gem。

Flow

Set of cross-platform libraries for RubyMotion

class HelloWorldScreen < UI::Screen
  def on_show
    self.navigation.hide_bar
  end

  def on_load
    background = UI::View.new
    background.flex = 1
    background.margin = 25
    background.background_color = :white
    view.add_child(background)

    label = UI::Label.new
    label.margin = [10, 10, 5, 10]
    label.text = "Hello world"
    label.text_alignment = :center
    background.add_child(label)
    view.update_layout
  end
end

了解更多

 

motion-game

Cross-platform game engine for RubyMotion

class HelloWorld < MG::Scene
  def initialize
    label = MG::Text.new("Hello World", "Arial", 96)
    label.anchor_point = [0, 0]
    add label
  end
end

了解更多

 

motion-cocoapods

Integrate 3rd-party libraries in RubyMotion for iOS / OS X projects via CocoaPods

Motion::Project::App.setup do |app|
 # ...
 app.pods do
   pod 'AFNetworking'
 end
end

了解更多

 

motion-gradle

Integrate 3rd-party Java dependencies in RubyMotion for Android projects using Gradle

Motion::Project::App.setup do |app|
  # ...
  app.gradle do
    dependency 'net.sf.ehcache:ehcache:2.9.0'
    dependency 'com.joanzapata.pdfview:android-pdfview:1.0.+@aar'
    dependency 'com.danikula:videocache:2.3.1' do
      exclude module: 'android', group: 'com.google.android'
    end
  end
end

了解更多

 

motion-appstore

A RubyMotion plugin to provide 'validate' and 'upload' commands for iTunes Connect.

$ motion upload me@example.com
Upload: ./build/iPhoneOS-8.1-Release/HelloWorld.ipa
 No errors uploading ./build/iPhoneOS-8.1-Release/HelloWorld.ipa

了解更多

 

motion-provisioning

Simplified provisioning for RubyMotion iOS, tvOS and macOS apps.

Motion::Project::App.setup do |app|
  app.name = 'My App'
  app.identifier = 'com.example.myapp'

  app.development do
    app.codesign_certificate = MotionProvisioning.certificate(
      type: :development,
      platform: :ios)

    app.provisioning_profile = MotionProvisioning.profile(
      bundle_identifier: app.identifier,
      app_name: app.name,
      platform: :ios,
      type: :development)
  end
end

了解更多

 

MotionKit

A layout and styling gem, from the authors of SugarCube and ProMotion. Encourages clean separation of application and view code.

class LoginLayout < MK::Layout
  def layout
    root :login_container do
      add UIImageView, :company_logo
      add UITextField, :username_field
      add UITextField, :password_field
    end
  end

  def company_logo_styles
    constraints do
      center_x.equals(:superview)
      top.equals(:superview).plus(40)
    end

    image UIImage.imageNamed('logo')
  end
end

了解更多

 

BubbleWrap

A collection of helpers and wrappers used to wrap CocoaTouch and AppKit code and provide more Ruby like APIs.

# Show Alerts
App.alert("BubbleWrap is awesome!")
App.alert("BubbleWrap is awesome!",
  { cancel_button_title: "Yes!", message: "Seriously." })

# Find device-specific information
Device.iphone?       # Is the device an iPhone?
Device.ipad?         # Is the device an iPad?
Device.camera.front? # Does the device have a front camera?

# Parse a JSON string to a Hash
BW::JSON.parse "{\"foo\":1,\"bar\":[1,2,3]}"

# Ruby DSL for NSUserDefaults
App::Persistence['numbers'] = { one: 1, two: 2, three: 3 }

# CoreLocation DSL
BW::Location.get_once(desired_accuracy: :best) do |result|
  if result.is_a?(CLLocation)
    puts result.coordinate
  else
    puts "ERROR: #{result[:error]}"
  end
end

了解更多

 

希望了解更多 Gem?访问 Motion Toolbox,以获取更全面的 Gem 列表。

需要获得更多帮助?

获取支持