Method: Walt.animate

Defined in:
lib/walt/walt.rb

.animate(animation = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/walt/walt.rb', line 24

def animate(animation = {})
  view = animation.delete(:in)

  self.pending_animations << animation

  self.pending_assets[animation.object_id] = animation[:assets].count
  animation[:assets].collect! do |asset|
    _asset = (asset.is_a?(Walt::Asset) ? asset : Walt::Asset.for(asset))
    _asset.on_ready do |a|
      self.pending_assets[animation.object_id] -= 1
      if self.pending_assets[animation.object_id] == 0
        self.trigger_animation(animation)
        self.pending_animations.delete(animation)
      end
    end
    view.addSubview(_asset.view)
    _asset.view.hidden = true
    _asset
  end
end