Happy Christmas Eve, Happy Winter Solstice, Happy coding

If you celebrate Christmas on the 25th, happy Christmas. As an avid runner, I personally welcome the Winter Solstice and the coming daylight. This issue is a short one due to the holidays, but don’t worry I still have my list of articles and posts from this week, I’ll add them to next week’s Dispatch.

Happy coding, Todd Werth (@twerth)

Poll of the Week


No poll this week, but here are the results from from last week’s poll “What editor or IDE do you use when developing in RubyMotion

Total votes: 40
Sublime Text: 38%
vim: 25%
RubyMine: 20%
TextMate: 15%
Other: 3%

Articles, News, and Blog Posts


This issue is a short one due to the holidays, but don’t worry I still have my list of articles and posts from this week, I’ll add them to next week’s Dispatch. (FYI, this section, by far, takes the longest to create). Issue #6 had tons of articles, which will hopefully get you through the week.

RubyMotion Tip


zPosition and z index

This is very confusing, especially if you come from the web world. There are two ways to change the z dimension:

zPosition: The zPosition only affects the UIView visually, it does not affect its actual order. Its z-order depends on its place in its parent’s subview array. In other words, the order you create the subviews is the z-order. To change the zPosition:

my_view.layer.zPosition = 10
In a rmq stylesheet or style block:
st.z_position = 10

z index: The order that the subview was added to its superview (addSubview, insertSubview, etc. Or in rmq: rmq.append, rmq.prepend, rmq.unshift, etc). You can change the z index by moving the view arround in the array, here are some methods for that:

my_view.bringSubviewToFront
my_view.sendSubviewToBack

RMQ News


What is RubyMotionQuery (RMQ) you ask? Check out this video or this site

Version 0.5.0 released, read about it here

Updates

  • New RMQ everywhere system. You no longer have to pass around rmq objects if you’re not in a controller (table cells for example)
    • rmq_did_create is deprecated, use rmq_build now
    • rmq works in any object
    • rmq.view_controller will auto-find the correct controller. You can manually set the controller of an rmq object if needed
    • In addition to rmq.create and rmq.append, there is rmq.build. Create creates a UIView but doesn’t’ append, append both creates and appends, build doesn’t create or append, but does initialize the view to work with rmq. All 3 methods will fire the “def rmq_build” in your custom view
  • Improved performance
  • Created WeakRef utilities to work around RM bugs
    • RubyMotionQuery::RMQ.weak_ref(my_object)
    • RubyMotionQuery::RMQ.weak_ref_to_strong_ref(my_weak_object)
  • Changed “end” to “back” in traversing. I can’t believe I created a method named “end”, I’m not very bright sometimes. I blinding named it what jQuery does. Next week I’ll create an “if” and “super” method  [;-)]
  • Added distribute (:vertical, :horizontal, :margin, :margins): rmq(UILabel).distribute
  • Added resize_to_fit_subviews
  • Added actions
    • enable
    • disable
    • enable_interaction
    • disable_interaction
  • Added to stylesheets:
    • screen_width
    • screen_height
    • content_width
    • content_height
    • content_size
  • Added to stylers:
    • clip_to_bounds
    • Changed styler#frame to accept a CGRect
    • Misc
  • Added some basic debug utilities. I will be adding more to this later. rmq.debug.assert
  • Bug fixes
    • Tons of misc fixes
    • Fixed memory leak where a controller was not being released
    • Fixed a few crashes
  • Updated various templates, such as view, controller, and collection view controller
    • New app template has the correct icons for iOS7
  • Update example app to include a collection view and navigation bar
  • Added Dash docset (Dash is a help OSX app)

 

RMQ Tips


Colors – RMQ has a variety of color helpers.

My guess is a committee at Apple that named the UIColor methods debated wether to name red either UIColor.redColor or UIColor.redColorForTheUI. The “concise” lobby won the day. That or they get paid by the character. 😉

Various ways to get a color:
rmq.color.red
rmq.color.from_hex(‘#ffffff’)
rmq.color.from_hex(‘ffffff’)
rmq.color.from_rgba(128, 128, 128, 0.5)

In a production app you really shouldn’t litter your code with magic colors. To solve that problem you can add your own named colors, like so:
rmq.color.add_named :pitch_black, ‘#000000’
Or
rmq.color.add_named :pitch_black, rmq.color.black

Then you can use that color anywhere in your app:
my_label.textColor = rmq.color.pitch_black

In a stylesheet you don’t need the “rmq”:

st.color = color.pitch_black

One more thing


Coming soon: I’m creating a 30-ish minute video building an image browsing app, from start to finish, using RMQ and AFMotion.


If you have any tips, blog posts, or want to sponsor this newsletter, please send emails to todd@infinitered.com