我目前正在为按钮和 View 添加动画
@button = UIButton.buttonWithType(UIButtonTypeRoundedRect)
@button.frame = [[0,0],[50,50]]
@button.setTitle("Click to move",forState:UIControlStateNormal)
@button.addTarget(self, action:'animate_button',forControlEvents:UIControlEventTouchUpInside)
view.addSubview @button
def animate_button
@button.frame = [[0,0],[0,0]]
UIView.beginAnimations(nil,context:nil)
UIView.setAnimationDuration(0.05)
UIView.setAnimationDelay(0.2)
UIView.setAnimationCurve(UIViewAnimationCurveEaseOut)
@button.frame = [[280,400],[50,50]]
UIView.commitAnimations
end
谁能帮忙使用高级动画
最佳答案
你看过方糖吗?它非常受欢迎——与 BubbleWrap 一起,它是 rubymotion 最常用的 gem 之一。它有越来越多的动画相关方法集合,并使用新的 block 语法(就像 Paul.s 提到的那样)
最通用的是 UIView.animation { animations_go_here }
UIView.animation {
my_view.frame = new_frame
# or apply a transform to a layer
my_view.layer.transform = CATransform3DMakeScale(2, 2, 1)
}
参见 Core Animation Function Reference以获得更多转换功能。
但是如果你想做一个“普通”的动画,你可以通过添加一些 UIView 来做很多事情:
my_view.slide :left, 100
my_view.move_to CGPoint.new(10, 20) # or [10, 20] works, too
my_view.fade_out
这些都采用类似的选项:
my_view.fade_out(duration: 1) # 1 second fade out
my_view.fade_out(delay: 1) # 1 second later, fade out
而且您可以轻松地将它们链接起来:
my_view.slide :left, 120 {
my_view.fade_out {
my_view.removeFromSuperview
}
}
它们可以分组:
UIView.animate {
my_view.slide :left, 120
my_view.fade_out
}
关于ios - 如何向 rubymotion 应用程序添加动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14626950/