2012-07-16 94 views
0

如何在RubyMotion中旋转图像?如何在RubyMotion中旋转图像?

+0

你尝试过什么?显示你的位置,并解释你的挣扎和某人可能真的会对你有帮助 – 2012-07-19 12:57:03

+0

感谢保罗 - 我实际列出并在审查步骤后,终于找到了答案。 – RedNax 2012-07-30 03:32:22

回答

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 
+0

这太棒了!你将如何翻译定位点? _view1是图层吗? ObjC中的例子在这里 - http://stackoverflow.com/questions/4072460/how-do-i-animate-rotate-a-uiview-90-degress-from-its-upper-right-corner – RedNax 2012-08-03 11:11:59

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