Class: Walt::Operation::RotateOperation

Inherits:
Base
  • Object
show all
Defined in:
lib/walt/operation/rotate.rb

Constant Summary collapse

PROPERTIES =
[:from, :to]

Instance Method Summary collapse

Methods inherited from Base

#setup

Methods included from Support::AttrDefault

#attr_default

Constructor Details

#initialize(params = {}) ⇒ RotateOperation

Returns a new instance of RotateOperation.



16
17
18
19
20
21
22
23
24
# File 'lib/walt/operation/rotate.rb', line 16

def initialize(params = {})
  super

  params.each do |key, value|
    if PROPERTIES.include?(key.to_sym)
      self.send("#{key}=", value)
    end
  end
end

Instance Method Details

#finalize(view, animation) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/walt/operation/rotate.rb', line 26

def finalize(view, animation)
  rotate = CABasicAnimation.animationWithKeyPath("transform.rotation")

  from = self.from || view.instance_variable_get("@__last_rotation") || 0
  rotate.fromValue = NSNumber.numberWithFloat(from)

  rotate.toValue = NSNumber.numberWithFloat(self.to * Math::PI / 180)
  view.instance_variable_set("@__last_rotation", rotate.toValue.to_f)

  rotate.duration = animation.duration
  rotate.removedOnCompletion = false
  rotate.fillMode = KCAFillModeForwards

  view.layer.addAnimation(rotate, forKey:nil)
end