Skip to content

AnimatorSetDemo.ag

xu_whale edited this page Sep 7, 2020 · 1 revision

copy下面代码,运行试试

model(userData)

animSet() {
    {
        type = Alpha,
        from = 1,
        to = 0.2,
        duration = 2,
    },
    {
        type = PositionX,
        from = 200,
        to = 10,
        duration = 2,
    },
    serial = true,--串行true,并行false
    start = userData.animStatus.start,
    pause = userData.animStatus.pause,
    resume = userData.animStatus.resume,
    stop = userData.animStatus.stop,

}

---
--- UI
ui {
    --- layout views
    Label("点我开始Color+Position动画")
    .padding(10, 30, 10, 30)
    .bgColor(Color(0xaaaaaa))
    .onClick(function()
        --方式1
        anim1 = ObjectAnimation(AnimProperty.Color, self)
        anim1.duration(2).from(200, 200, 0, 1).to(0, 0, 200, 1)

        anim2 = ObjectAnimation(AnimProperty.Position, self)
        anim2.duration(2).from(10, 10).to(100, 50)

        animSet1 = AnimatorSet().together({ anim1, anim2 })
        animSet1.start()
    end)
    ,
    Label("Alpha+PositionX动画")
    .top(50)
    .height(100)
    .bgColor(Color(0x799900))
    --添加动画
    .animation(animSet())
    ,
    Label("点我开始Alpha+PositionX动画")
    .top(20)
    .padding(10, 30, 10, 30)
    .bgColor(Color(0xaaaaaa))
    .onClick(function()
        --方式2
        userData.animStatus.start = true
    end)
    ,
    Label("点我暂停Alpha+PositionX动画")
    .top(20)
    .padding(10, 30, 10, 30)
    .bgColor(Color(0xaaaaaa))
    .onClick(function()
        userData.animStatus.start = false
        userData.animStatus.pause = true
    end)
}.safeArea(SafeArea.TOP)

---
--- preview
local function preview()

    userData.animStatus = {
        start = false,
        pause = false,
        resume = false,
        stop = false }

end
Clone this wiki locally