SwiftUI 辅助功能 VoiceOver 焦点问题

问题描述 投票:0回答:1

我的屏幕上有一个按钮,点击该按钮我将打开一个模式(视图)。但关闭该视图后,辅助功能 VoiceOver 焦点将转到屏幕的左上角元素。我希望关闭该视图后焦点保持在同一个按钮上。

ios swiftui accessibility voiceover
1个回答
0
投票
// State variable to control loading state
@State var isLoading: Bool = false
    
// Accessibility focus state variable to manage focus
@AccessibilityFocusState var isLoadingIndicatorFocused: Bool
    
var body: some View {
    VStack {
        Button("Search Appt website") {
            // Set loading state to true
            isLoading = true
            // Move focus to the loading indicator
            isLoadingIndicatorFocused = true
        }
            
        if isLoading {
            ProgressView()
                .accessibilityFocused($isLoadingIndicatorFocused)  // Bind the focus state
                .accessibilityLabel("Loading")  // Provide an accessible label
            }
        }
    }

参考:https://appt.org/en/docs/swiftui/samples/accessibility-focus#:~:text=Accessibility%20focus%20%2D%20SwiftUI,特定%20element%20in%20your%20app

© www.soinside.com 2019 - 2024. All rights reserved.