sugarcube v0.2.5

New features:

  • delayed execution added to Numeric
  • more constants added to Symbol
  • more UIView animation quickies (if nothing else, check out shake)
  • UINavigationController additions
  • more REPL adjusters
  • more core graphic stuff

    gem install sugarcube

delayed execution

1.5.seconds.later do  # 1.minute.later, 4.hours.later
  view.fade_out { view.removeFromSuperview }
end

constants added to Symbol

( :large | :white | :gray ).uiactivityindicatorstyle # aka uiactivityindicatorviewstyle
( :plain | :grouped ).uitablestyle # aka uitableviewstyle
( :default | :black | :translucent ).uistatusbarstyle
( :default | :landscape ).uibarmetrics
( :done | :cancel ... | :pagecurl ).uibarbuttonitem  # there are lots of these
( :default | :asciicapable | :url | :numberpad | :phonepad | :namephonepad | :emailaddress | :numbersandpunctuation).uikeyboardtype

UIView animation quickies

shake is so cool :-)

# these are immediate - no duration option (use fade_{in|out})
view.show
view.hide

view.fade_in
view.fade_out 0.3
view.fade_in(duration: 0.3, delay: 0.3)

# really easy to animate views in from stage right, or to exit stage left
view.slide :left


# SHAKE!

# this is great on a UIButton after an invalid form submission
# think Apple's shaking login window
view.shake

# vigourous nodding (up+down)
view.shake offset: 20, repeat: 10, duration: 5, keypath: 'transform.translation.y'

# wiggling, using keypath: 'transform.rotation'
view.shake offset: 0.1, repeat: 2, duration: 0.5, keypath: 'transform.rotation'

UINavigationController

the two important ones:

nav_controller << other_controller
nav_controller.pop
# pushing
# nav_controller.pushViewController(next_view_controller, animated: true)
nav_controller.push next_view_controller
nav_controller << next_view_controller

# popping some or all
nav_controller.pop  # nav_controller.popViewControllerAnimated(true)
nav_controller.!  # nav_controller.popToRootViewControllerAnimated(true)
nav_controller.!(other_view)  # nav_controller.popToViewController(other_view, animated: true)
nav_controller.pop(other_view)  # nav_controller.popToViewController(other_view, animated: true)

REPL adjusters

Once you command+click on a view you wanna mess with, you might need to subviews/superview you way to the view you ACTUALLY want to modify. assign it to the adjusters using a self.superview.subviews[1] (aka adjust self.superview.subviews[1])

You need to include SugarCube::Adjust, or prefix with that module name

> a self.superview.subviews[1]

# access the view
> a.subviews.length
=> 0

# access or assign the frame, which returns a CGRectArray object
> f
=> [[0.0, 0.0], [320.0, 480.0]]
> f [[1,1], [318, 478]]

# NEW!  change the shadow
> shadow opacity: 0.5, radius: 5, offset: [0, 1], color: :white
# alias is `h` (`s` is "shorter")
> h opacity: 0.5, radius: 5, offset: [0, 1], color: :white
# view the shadow
> h
=> {:opacity=>0.5, :radius=>5.0, :offset=>#<CGSize width=0.0 height=1.0>, :color=>#<__NSCFType:0x8b0c550>, :path=>nil}

# restore restores the frame AND the shadow
> restore

core graphics

Added UIKit additions, and lots of ways to add CG objects

You need to include SugarCube::CoreGraphics, or prefix with that module name.

uikit additions

> EdgeInsets(0, 1, 2, 3)  # (top, left, bottom, right)
=> UIEdgeInsets(0, 1, 2, 3)

> EdgeInsets(5)
=> UIEdgeInsets(5, 5, 5, 5)

> Offset(1, 1)  # (horizontal, vertical)
=> UIOffset(1, 1)

add CG objects

# add two Rects, you'll get a bigger rect that encompasses BOTH Rects
> Rect([[1, 1], [10, 10]]) + Rect([[0, 1], [5, 20]])
=> Rect([[0, 1], [11, 20]])

# rect + point moves the rect as if point were a vector
> Rect(1, 1, 10, 10) + Point(9, 9)
=> Rect([[10, 10], [10, 10]])

# rect + size makes the rect bigger
> Rect(1, 1, 10, 10) + Size(9, 9)
=> [[1, 1], [19, 19]]

# point + point == point + offset
> Point(10, 10) + Point(1,1)
=> Point(11, 11)

# point + size = size + point => Rect(point, size)
> Point(1, 1) + Size(10, 10)
=> Rect([1, 1], [10, 10])