Sha256: fbbd1eadd64ed7178610802541c45b9199b838a2c357f583e3a25864dff90dc3

Contents?: true

Size: 971 Bytes

Versions: 1

Compression:

Stored size: 971 Bytes

Contents

=begin
  {
    from: 1.0,
    to: 1.2
  }
=end

module Walt
  module Operation
    class ScaleOperation < 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)
        scale = CABasicAnimation.animationWithKeyPath("transform.scale")

        from = self.from || view.instance_variable_get("@__last_scale") || 1.0
        scale.fromValue = NSNumber.numberWithFloat(from)

        scale.toValue = NSNumber.numberWithFloat(self.to)
        view.instance_variable_set("@__last_scale", scale.toValue.to_f)

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
walt-0.1 lib/walt/operation/scale.rb