Skip to content

Instantly share code, notes, and snippets.

@twerth
Created April 3, 2013 02:24
Show Gist options
  • Save twerth/5297956 to your computer and use it in GitHub Desktop.
Save twerth/5297956 to your computer and use it in GitHub Desktop.
RubyMotion: Adding a block to Teacup's animate_to_style, for completion
# RubyMotion: Adding a block to Teacup's animate_to_style, for completion. You can do something like this
#
# popup.animate_to_style( duration: 0.9, left: 5) do |finished|
# popup.animate_to_style( duration: 0.3, left: 105) do |finished|
# popup.animate_to_style( duration: 0.5, top: 300) do |finished|
# popup.hidden = true
# end
# end
# end
#
class UIView
def animate_to_style(opts = {}, &block)
UIView.animateWithDuration(
opts.delete(:duration) || 0.3,
delay: opts.delete(:delay) || 0,
options: (opts.delete(:options) || UIViewAnimationOptionCurveEaseInOut),
animations: lambda { style(opts) },
completion: block)
self
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment