0

如何在 RubyMotion 中旋转图像?

4

2 回答 2

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
于 2012-07-26T04:03:50.583 回答
3

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

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
于 2012-07-30T21:09:31.257 回答