0

How to rotate an image in RubyMotion?

RedNax
  • 1,507
  • 1
  • 10
  • 20
  • What have you tried? Show where you got to and explain how your struggling and someone may actually take an interest in helping you – Paul.s Jul 19 '12 at 12:57
  • Thanks Paul - I actually listed it out and in review of the steps, finally found the answer. – RedNax Jul 30 '12 at 03:32

2 Answers2

3

Finally found it, using 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
RedNax
  • 1,507
  • 1
  • 10
  • 20
3

If you're looking for a raw Obj-C to RubyMotion conversion, we have it completed 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
Matt Garrison
  • 539
  • 3
  • 11
  • This is great! How would you translate the anchorpoint? Is the _view1 the layer? The example in ObjC is here - http://stackoverflow.com/questions/4072460/how-do-i-animate-rotate-a-uiview-90-degress-from-its-upper-right-corner – RedNax Aug 03 '12 at 11:11