Skip to content

Instantly share code, notes, and snippets.

@melvynhills
Created February 25, 2014 16:25
Show Gist options
  • Save melvynhills/9212324 to your computer and use it in GitHub Desktop.
Save melvynhills/9212324 to your computer and use it in GitHub Desktop.
RubyMotion UIView animation wrapper
class Animation
def initialize(duration, animations, completion=nil, delay=0, additionalOptions=nil)
if duration + delay == 0
animations.call
completion.call if completion
return
end
options = UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionCurveEaseOut
if additionalOptions
options = options | additionalOptions
end
UIView.animateWithDuration(duration,
delay: delay,
options: options,
animations: lambda { animations.call },
completion: lambda { |finished| completion.call if finished && completion }
)
end
end
# Simple usage
Animation.new 0.2, -> {
myLabel.alpha = 1.0
}
# Advanced usage
Animation.new 0.2, -> {
myLabel.alpha = 1.0
}, -> {
myLabel.text = 'complete'
}, 0.5, UIViewAnimationOptionCurveEaseIn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment