-
Notifications
You must be signed in to change notification settings - Fork 208
FrameAnimationDemo.lua
xu.jingyu edited this page Dec 24, 2019
·
4 revisions
copy下面代码,运行试试
local screen_w = window:width()
local screen_h = window:height()
local cardHeight = screen_h / 2 - 32 * 2
local baseView = View()
baseView:width(screen_w - 32):height(screen_h - 32):y(16):x(16):bgColor(Color(233, 233, 233, 1))
window:addView(baseView)
local linear1 = View()
linear1:x(20):width(screen_w - 40 - 32):height(cardHeight):y(16):bgColor(Color(255, 255, 255, 1))
local t1 = Label()
t1:onClick(function()
Toast("keye", 1)
end)
t1:text('Animation'):fontSize(18):textColor(Color(255, 255, 255, 1))
--t1:frame(Rect(50, 0, 100, 100))
--t1:marginLeft(50):marginTop(0)
--t1:width(100):height(100)
t1:bgColor(Color(99, 99, 99, 1))
linear1:addView(t1)
baseView:addView(linear1)
local linear2 = View()
linear2:x(20):width(screen_w - 40 - 32):height(cardHeight):y(screen_h - cardHeight - 32 - 16):bgColor(Color(255, 255, 255, 1))
local t21 = Label():fontSize(18):textColor(Color(255, 255, 255, 1))
t21:onClick(function()
Toast("keye", 1)
end)
t21:text('FrameAnimation')
--t21:frame(Rect(50, 0, 100, 100))
--t21:marginLeft(50):marginTop(0)
--t21:width(100):height(100)
t21:bgColor(Color(99, 99, 99, 1))
linear2:addView(t21)
baseView:addView(linear2)
if animation == nil then
animation = Animation()
animation:setAutoBack(false)
animation:setTranslateX(0, 50)
--animation:setTranslateY(0, 50)
animation:setScaleX(1, 0.7)
--animation:setScaleY(1, 0.7)
animation:setAlpha(1, 0.5)
animation:setDuration(2)
animation:setDelay(0.3)
animation:setInterpolator(InterpolatorType.AccelerateDecelerate)
animation:setEndCallback(function(isFinished)
Toast("animation end fck U "..tostring(isFinished),1)
print("animation end fck U ", isFinished)
end)
--animation:setRepeat(RepeatType.REVERSE, 8)
end
if frameAnimation == nil then
frameAnimation = FrameAnimation()
frameAnimation:setDuration(2)
frameAnimation:setTranslateX(ValueType.CURRENT, 100)
--frameAnimation:setTranslateXTo(150)
--frameAnimation:setTranslateY(ValueType.CURRENT, 100)
--frameAnimation:setTranslateX(50,150)
--frameAnimation:setTranslateY(0,90)
--frameAnimation:setScaleWidthTo(100*0.8)
--frameAnimation:setScaleHeightTo(100*0.8)
frameAnimation:setScaleWidth(ValueType.CURRENT, 100 * 0.5)
--frameAnimation:setScaleHeight(ValueType.CURRENT, 100 * 0.5)
--frameAnimation:setBgColorTo(Color(0, 222, 222, 1))
frameAnimation:setAlphaTo(0.5)
frameAnimation:setInterpolator(InterpolatorType.AccelerateDecelerate)
--frameAnimation:setDelay(0.3)
--frameAnimation:needRepeat()
--frameAnimation:needAutoreverseRepeat()
frameAnimation:setEndCallback(function()
Toast("frameAnimation end fck U", 1)
print("frameAnimation end fck U")
end)
end
local reloadBtn = Label()
reloadBtn:x(screen_w - 110):y(20):width(100):height(50):bgColor(Color(222, 222, 222, 1))
reloadBtn:text("Reload:Linear"):textAlign(TextAlign.CENTER)
reloadBtn:fontSize(13)
reloadBtn:onTouch(function(x, y)
t1:frame(Rect(50, 0, 100, 100))
t21:marginLeft(50):marginTop(0)
t21:width(100):height(100)
System:setTimeOut(function()
animation:start(t1)
frameAnimation:start(t21)
end, 1)
end)
window:addView(reloadBtn)
local reloadBtn = Label()
reloadBtn:x(screen_w - 110):y(90):width(100):height(50):bgColor(Color(222, 222, 222, 1))
reloadBtn:text("Reload:Frame"):textAlign(TextAlign.CENTER)
reloadBtn:fontSize(13)
reloadBtn:onTouch(function(x, y)
t1:frame(Rect(50, 0, 100, 100))
t21:frame(Rect(50, 0, 100, 100))
System:setTimeOut(function()
animation:start(t1)
frameAnimation:start(t21)
end, 1)
end)
window:addView(reloadBtn)
local reloadBtn = Label()
reloadBtn:x(screen_w - 110):y(150):width(100):height(50):bgColor(Color(222, 222, 222, 1))
reloadBtn:text("Cancel anim"):textAlign(TextAlign.CENTER)
reloadBtn:fontSize(13)
reloadBtn:onTouch(function(x, y)
animation:stop()
end)
window:addView(reloadBtn)