如何在RubyMotion中旋转图像?

时间:2012-07-16 08:09:28

标签: rubymotion

如何在RubyMotion中旋转图像?

2 个答案:

答案 0 :(得分:3)

最后使用Teacup找到它。

Teacup::Stylesheet.new :main do
  style :rpng,
    image: UIImage.imageNamed("image.png"),
    frame: ([[50, 50], [70, 30]]),
    layer: {
      transform: rotate(identity, pi/3, 0.3, 0.3, 0.3)
    }
end

答案 1 :(得分:3)

如果您正在寻找原始的Obj-C到RubyMotion转换,我们已完成here

class RootController < UIViewController

  def viewDidLoad
    super
    xcode_image = UIImage.imageNamed("ilabs.png")

    @xcode_image_view1 = UIImageView.alloc.initWithImage(xcode_image)

    @xcode_image_view1.setFrame(CGRectMake(0,0,100,100))

    view.backgroundColor = UIColor.whiteColor
    view.addSubview(@xcode_image_view1)
  end

  def viewDidAppear paramAnimated
    super

    @xcode_image_view1.center = view.center
    UIView.beginAnimations("xcodeImageView1Animation", context:nil)

    UIView.setAnimationDuration(5)

    UIView.setAnimationDelegate(self)

    UIView.setAnimationDidStopSelector('clockwiseRotationDidStop:finished:context:')

    @xcode_image_view1.transform = CGAffineTransformMakeRotation(3.141592654 / 2)

    UIView.commitAnimations

  end

  def clockwiseRotationDidStop(paramAnimationID, finished:paramFinished, context:paramContext)
    p "Animation Finished now rotate back"

    UIView.beginAnimations("xcodeImageView1AnimationBack", context:nil)

    UIView.setAnimationDuration(5)

    @xcode_image_view1.transform = CGAffineTransformIdentity

    UIView.commitAnimations
  end
end