Created
          February 25, 2014 16:25 
        
      - 
      
- 
        Save melvynhills/9212324 to your computer and use it in GitHub Desktop. 
    RubyMotion UIView animation wrapper
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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