找回密码
马上加入

QQ登录

只需一步,快速开始

搜索
发新帖

0

收听

0

听众

2

主题
发表于 2024-7-11 13:19:43 | 查看: 579| 回复: 3

微信截图_20240711131905.png

    local container = GUI:Layout_Create(ImageView, "container", 0, 54.00, 800.00, 400.00, false)
    GUI:Layout_setBackGroundColorType(container, 1)
    GUI:Layout_setBackGroundColor(container, "#96c8ff")

    local containerSize = GUI:getContentSize(container)
    local centerX, centerY = containerSize.width / 2, containerSize.height / 2
    local a, b = 300, 100  -- 椭圆的长轴和短轴
    local viewCount = 10
    local images = {}
    local nowRadian = {}
    local touchStartX = 0
    local isTouching = false

    -- 计算椭圆各个控件的落点坐标
    local function getEllipsePointAt(radian)
        return {
            x = a * math.cos(radian) + centerX,
            y = b * math.sin(radian) + centerY,
        }
    end

    -- 计算权重
    local function getWeight(y)
        local weight = 1 - (y - (centerY - b)) / (2 * b)
        if weight < 0.5 then
            weight = 0.5
        elseif weight > 1 then
            weight = 1
        end
        return weight
    end

    -- 更新视图
    local function updateView()
        for i = 1, viewCount do
            local point = getEllipsePointAt(nowRadian[i])
            local image = images[i]

            GUI:setPosition(image, point.x, point.y)

            local weight = getWeight(point.y)
            GUI:setScale(image, weight)
            GUI:setOpacity(image, 255 * weight)
            GUI:setLocalZOrder(image, math.floor(weight * 10))
        end
    end

    -- 初始化界面
    local function initView()
        for i = 1, viewCount do
            local radian = (math.pi * 2) / viewCount * i
            local point = getEllipsePointAt(radian)
            local image = GUI:Image_Create(container, "img" .. i, point.x, point.y, string.format("res/public/word_fubentg_%d.png", i))
            GUI:setAnchorPoint(image, 0.5, 0.5)
            nowRadian[i] = radian
            images[i] = image

            local weight = getWeight(point.y)
            GUI:setScale(image, weight)
            GUI:setOpacity(image, 255 * weight)
            GUI:setLocalZOrder(image, math.floor(weight * 10))
        end
    end

    -- 处理触摸事件
    local function onTouchBegan(x)
        touchStartX = x
        isTouching = true
    end

    local function onTouchMoved(x)
        if isTouching then
            local deltaX = x - touchStartX
            touchStartX = x
            local angleChange = deltaX / 100  -- 调整滑动速度
            for i = 1, viewCount do
                nowRadian[i] = nowRadian[i] + angleChange
            end
            updateView()
        end
    end

    local function onTouchEnded()
        isTouching = false
    end

    -- 注册触摸事件
    GUI:setTouchEnabled(container, true)
    GUI:addOnTouchEvent(container, function(sender, type)
        if type == 0 then  -- 触摸开始
            local location = GUI:getTouchBeganPosition(sender)
            onTouchBegan(location.x)
        elseif type == 1 then  -- 触摸移动
            local location = GUI:getTouchMovePosition(sender)
            onTouchMoved(location.x)
        elseif type == 2 or type == 3 then  -- 触摸结束或取消
            local location = GUI:getTouchEndPosition(sender)
            onTouchEnded()
        end
    end)

    -- 调用初始化函数
    initView()
发表于 2024-12-10 22:20:47 IP属地:江苏省苏州市

大佬,请问怎么实现自动滚动的效果啊,能给个例子嘛

回复 显示全部楼层 道具 举报

发表于 2024-7-17 17:07:56 IP属地:辽宁省大连市

为啥计算坐标要用 sin,cos, 难道这个函数方便计算???

回复 显示全部楼层 道具 举报

发表于 2024-7-11 22:50:04 IP属地:江苏省徐州市
老铁就是给力!

回复 显示全部楼层 道具 举报

您需要登录后才可以回帖 登录 | 马上加入

QQ|Archiver|手机版|小黑屋|alg阿灵戈社区 ( 苏ICP备2023026137号-1|苏ICP备2023026137号-1 )

GMT+8, 2025-3-13 01:40 , Processed in 0.981684 second(s), 31 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表