根据你之前的代码逻辑分析,当 `i = 1` 时确实应该置灰,这是因为你的逻辑表达式 `(i == self.select) and false or true` 的计算结果问题。
在你的代码中:
```lua
self.select = 1
for i = 1, 6 do
local num = (i == self.select) and false or true
print(num)
UILib:setGrey(Button_1, num)
end
```
当 `i = 1` 时:
- `(1 == 1)` 为 `true`
- `true and false or true` 在Lua中会先计算 `true and false` 得到 `false`
- 然后 `false or true` 得到 `true`
- 所以 `num = true`
- `UILib:setGrey(Button_1, true)` 表示置灰
这是Lua逻辑运算符的优先级规则:`and` 的优先级高于 `or`。如果你想实现"选中时不置灰,未选中时置灰"的效果,需要调整逻辑。
建议修改为:
```lua
local num = (i == self.select) -- 选中时为true,未选中时为false
UILib:setGrey(Button_1, not num) -- 选中不置灰,未选中置灰
```
或者更直观的写法:
```lua
if i == self.select then
UILib:setGrey(Button_1, false) -- 选中状态,不置灰
else
UILib:setGrey(Button_1, true) -- 未选中状态,置灰
end
```