我是 Core Animation 的新手,也是 RubyMotion 的新手(自 1 月以来一直在 Xcode 中使用 Obj-C)。我需要 AppLabel (它的 png 在名为 AppAppearance.rb 的文件中指定,但它加载的所有动画都在此文件中)。现在我正在使用 animateWithDuration 但是当标签加载时我需要向左反弹。任何可能的帮助将不胜感激,我整天都在转圈。我正在尝试使用以下代码:将图像退回以查看以及我可以在 CAKeyFrameAnimation 上找到的任何内容,但我在将 Obj-C 转换为 Ruby 时遇到了困难。谢谢!
class AppLabel < UILabel
#-------------------------
DefaultHeight = 45
DefaultWidth = 170
def initWithFrame( frame )
#-------------------------
if ( super( frame ) )
@showing = false
@hiding = false
self.size.width = 170 if self.size.width == 0
self.size.height = 46 if self.size.height == 0
self.backgroundColor = AppAppearance.appLabelBackgroundColor
self.font = AppAppearance.fontWithSize( 14 )
self.textColor = AppAppearance.appLabelTextColor
self.numberOfLines = 2
end
self
end
#
# method. drawTextInRect
#
def drawTextInRect( rect )
#-------------------------
rect.origin.x += 10
rect.origin.y += 2
rect.size.width -= 30
super( rect )
end
#
# method. show
#
def show
#-------
if ( ( self.hidden? || self.alpha < 1 ) && !@showing )
if self.hidden?
self.alpha = 0.0
self.hidden = false
end
@showing = true
UIView.animateWithDuration(
1.0,
animations: lambda do
self.alpha = 1.0
end,
completion: lambda do | finished |
@showing = false
end
)
end
end
#
# method. hide
#
def hide
#-------
unless ( self.hidden? || self.alpha == 0 || @hiding )
log( 'hiding' )
@hiding = true
UIView.animateWithDuration(
1.0,
animations: lambda do
self.alpha = 0.0
end,
completion: lambda do | finished |
self.hidden = true
@hiding = false
end
)
end
end
end