Class: CAAnimation

Inherits:
Object show all
Defined in:
lib/cocoa/sugarcube-animations/caanimation.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.basic(key_path, options = {}, &block) ⇒ Object

If you pass a block, that block will be called at the end of the animation.



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cocoa/sugarcube-animations/caanimation.rb', line 32

def basic(key_path, options={}, &block)
  animation = CABasicAnimation.animationWithKeyPath(key_path)
  _sugarcube_apply_animation_options(animation, options)
  fill_mode = options.fetch(:fill_mode, KCAFillModeForwards)
  animation.fillMode = fill_mode

  animation.fromValue = options[:from] if options.key?(:from)
  animation.toValue = options[:to] if options.key?(:to)
  animation.byValue = options[:by] if options.key?(:by)

  return animation
end

.keyframe(key_path, options = {}, &block) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cocoa/sugarcube-animations/caanimation.rb', line 45

def keyframe(key_path, options={}, &block)
  timing_function = options.fetch(:timing, KCAMediaTimingFunctionDefault)
  fill_mode = options.fetch(:fill_mode, KCAFillModeForwards)

  animation = CAKeyframeAnimation.animationWithKeyPath(key_path)
  _sugarcube_apply_animation_options(animation, options)
  animation.fillMode = fill_mode

  if options.key?(:values)
    animation.values = options[:values]
  elsif options.key?(:path)
    path = options[:path]
    if path.is_a?(UIBezierPath)
      path = path.CGPath
    end
    animation.path = path
  end

  return animation
end

Instance Method Details

#completion(&completion) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/cocoa/sugarcube-animations/caanimation.rb', line 68

def completion(&completion)
  if completion
    unless self.delegate.is_a?(SugarCubeAnimationDelegate)
      delegate = SugarCubeAnimationDelegate.new
      self.delegate = delegate
    end
    self.delegate.completion = completion.weak!
  elsif self.delegate.is_a?(SugarCubeAnimationDelegate)
    return self.delegate.completion
  end
end

#start(&start) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/cocoa/sugarcube-animations/caanimation.rb', line 80

def start(&start)
  if start
    unless self.delegate.is_a?(SugarCubeAnimationDelegate)
      delegate = SugarCubeAnimationDelegate.new
      self.delegate = delegate
    end
    self.delegate.start = start.weak!
  elsif self.delegate.is_a?(SugarCubeAnimationDelegate)
    return self.delegate.start
  end
end