GUI:setVisible
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-04-16 17:41:12 |
👁️ 阅读: 2
`GUI:setVisible(widget, value)` 是996引擎中用于设置控件可见性的函数。
**函数说明:**
- **widget**:控件对象(必填)
- **value**:布尔值,true表示显示,false表示隐藏
**使用示例:**
```lua
-- 创建父节点
local parent = GUI:Win_Create("GMMain", 0, 0, 0, 0, false, false, true, false, false, false, 1)
-- 创建按钮
local button = GUI:Button_Create(parent, "btn_test", 100, 100, "res/public/1900000612.png")
GUI:Button_setTitleText(button, "测试按钮")
-- 设置按钮可见
GUI:setVisible(button, true)
-- 设置按钮不可见
GUI:setVisible(button, false)
-- 创建文字控件
local text = GUI:Text_Create(parent, "Text_test", 200, 200, 16, "#ffffff", "测试文字")
-- 切换文字可见性
local isVisible = true
GUI:addOnClickEvent(button, function()
isVisible = not isVisible
GUI:setVisible(text, isVisible)
SL:print("文字可见性:" .. tostring(isVisible))
end)
```
**注意事项:**
1. 设置控件不可见后,控件将不响应触摸事件
2. 与`setTouchEnabled()`配合使用可以控制交互状态
3. 常用于界面元素的显示/隐藏切换
**结合透明度使用:**
```lua
-- 先设置透明度再设置可见性
GUI:setOpacity(text, 255) -- 设置不透明度
GUI:setVisible(text, true) -- 显示控件
```
这个函数在前端开发中非常常用,用于控制界面元素的显示状态。
← 返回问答库