You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TabView开启VoiceOver后选中索引自动重置为0的问题求助

VoiceOver开启时TabView获取焦点会重置selectedIndex的问题

我用TabView实现了一个简单的引导页,发现开启VoiceOver后,当TabView获得焦点时,绑定的selectedIndex变量会自动重置为0。

复现代码

struct ContentView: View {
    @State var selectedIndex = 0
    var body: some View {
        VStack {
            Text("Header")
            TabView(selection: $selectedIndex) {
                ForEach((0...2), id: \.self) { index in
                    Button {
                        selectedIndex += 1
                    } label: {
                        Text("at: \(selectedIndex), Goto Next Tab")
                    }
                    .tag(index)
                }
            }
            .tabViewStyle(.page(indexDisplayMode: .never))
            .indexViewStyle(.page(backgroundDisplayMode: .never))
            Text("Footer")
        }
        .padding()
    }
}

Accessibility Inspector检查结果

Before Focus
After Focus

内容的提问来源于stack exchange,提问作者Ali

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 23:15:57