Sha256: 69930c12f3df44a3fd05b1d8fcffe3ab858ccec5c0ceea79d8d6cfd2e5221989

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

motion_require "base"

=begin
  {
    from: 0,
    to: 45
  }
=end

module Walt
  module Operation
    class RotateOperation < Base
      PROPERTIES = [:from, :to]
      attr_accessor *PROPERTIES

      def initialize(params = {})
        super

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

      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
walt-0.1.2 lib/walt/operation/rotate.rb