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

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

constants added to Symbol

ruby ( :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 :-)

“`ruby

these are immediate - no duration option (use fade_{in|out})

view.show view.hide

view.fadein view.fadeout 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:

ruby nav_controller << other_controller nav_controller.pop

“`ruby

pushing

navcontroller.pushViewController(nextview_controller, animated: true)

navcontroller.push nextviewcontroller navcontroller << nextviewcontroller

popping some or all

navcontroller.pop # navcontroller.popViewControllerAnimated(true) navcontroller.! # navcontroller.popToRootViewControllerAnimated(true) navcontroller.!(otherview) # navcontroller.popToViewController(otherview, animated: true) navcontroller.pop(otherview) # navcontroller.popToViewController(otherview, 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

“`ruby

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=>#, :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

”`ruby

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

”`ruby

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]) “`