点击按钮渐显渐隐指定控件
点击按钮渐显渐隐指定控件
功能:点击指定按钮使控件切换可见性并切换效果为逐渐显示逐渐淡隐。
local showbtnId = 100136--显示按钮idlocal hidebtnId = 100776--隐藏按钮idlocal uiId = 100159--指定控件id
self.timer--定时器local transparency = 0--透明度local change = 0.1--每次渐变值local visible = false--显隐状态
-- @description: 控件渐显渐隐local function FadeIn(id, num)    --停止上一个定时器打断控件之前的渐变    TimerManager:RemoveTimer(timer)        --添加一个新的定时器开始新的渐变        self.timer = TimerManager:AddLoopTimer(0.1, function ()            --透明度变化直到为0或100时停止            transparency = transparency + num            if transparency < 0 then            transparency = 0            TimerManager:RemoveTimer(self.timer)            end            if( transparency > 1) then            transparency = 1            TimerManager:RemoveTimer(self.timer)        end        --渐变效果        UI:SetTransparency({id},transparency)--设置控件透明度    end)end
function GameClient:OnStart()    --初始显示指定控件    UI:SetVisible({uiId},true)    --初始设置指定控件透明度为0    visible = false    UI:SetTransparency({uiId},0)    --绑定按钮    UI:RegisterPressed(showbtnId,function(Iteam,PosX,PosY)        if visible == false then            --渐显            FadeIn(uiId, change)            visible = true            UI:ShowMessageTip("渐显")            UI:SetText({showbtnId},"渐显")        else            --渐隐            FadeIn(uiId, -change)            visible = false            UI:ShowMessageTip("渐隐")            UI:SetText({showbtnId},"渐隐")        end    end)end