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