Gems

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

RubyMotionQuery

A fast, non-polluting, chaining, front-end library. It’s like jQuery plus templates, stylesheets, events, animations, and more.

rmq.append(UIButton, :save_buttton).on(:touch) do |sender|
  rmq(sender).animations.sink_and_throb
  rmq.animations.start_spinner
  my_model.save completion: -> {
    rmq.animations.stop_spinner
  }
end

def save_buttton(st) # Style for button above
  st.frame = {
    width: 150, height: 30,
    from_right: 10, from_bottom: 20
  }
  st.background_color = color.blue
  st.text = 'Save'
end

rmq(section_view).find(UIImageView).and(hidden: true).show

了解更多

 

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

了解更多

 

ProMotion

A clean, Ruby-style syntax for building default and custom navigation screens in a RubyMotion app.

class AppDelegate < PM::Delegate
  def on_load(app, options)
    open HomeScreen.new(nav_bar: true)
  end
end

class HomeScreen < PM::Screen
  title "Home"

  def on_load
    set_attributes self.view, {
      background_color: hex_color("#FFFFFF")
    }
  end
end

了解更多

 

Sugarcube

A set of Ruby extensions for CocoaTouch/iOS, to make development more enjoyable.

# Convert String and Symbol to UIFont and UIColor
label = UILabel.new
label.font = 'Helvetica'.uifont
label.backgroundColor = :clear.uicolor

# Rubyesque code (normally be `view.addSubview(label)`)
self.view << label

# Animations and unit conversions
label.fade_in(duration: 1.minute)

# Timers and presenting an alert on the current controller
2.minutes.later do
  UIAlertController.alert(self, 'Ain’t SugarCube grand!?',
    message: 'Tell me your honest opinion',
    buttons: {
      yes: 'Yes, it is',
      for_sure: 'For *sure*!',
    }) do |choice|
       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

了解更多

 

CoreDataQuery

A library to help you manage your CoreData stack while using RubyMotion.

class Vat < CDQManagedObject
  scope :size_range do |low, high|
    where(:capacity_liters).ge(low).and.lt(hi)
  end

  scope :medium, size_range(50, 100)
  scope :pvc, where(:material).eq('PVC')
end

vat = Vat.medium.order(:capacity).pvc.first.get
vat.brand = "Acme"

cdq.save

了解更多

 

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

需要获得更多帮助?

获取支持