简体   繁体   English

iOS辅助功能,如何在关闭警报后重点关注最后一项

[英]iOS Accessibility, how to make focus go back to the last item after dismiss the alert

I have a button and when I tap the button, there will be an alert. 我有一个按钮,当我点击按钮时,会有一个警报。

When I have voiceover on and tap the button, then tap the alert OK button to dismiss the alert, the focus will go back to the top of the page/back button, rather than the button that triggers the alert. 当我打开画外音并点击按钮时,点击警报确定按钮以关闭警报,焦点将返回到页面/后退按钮的顶部,而不是触发警报的按钮。

I'm using this chunk of code to move the focus back to the button: 我正在使用这段代码将焦点移回按钮:

let dispatchTime: dispatch_time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(0 * Double(NSEC_PER_SEC)))

dispatch_after(dispatchTime, dispatch_get_main_queue(), {
  UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, button)
})

The problem is after you dismiss the alert, the focus will go back to the top and read the label first, then go back to the button. 问题是在您关闭警报后,焦点将返回到顶部并首先读取标签,然后返回按钮。 The focus is not going to the button directly, which looks pretty lame. 重点不是直接按钮,看起来很蹩脚。

I checked some Apple app, and I find that after they dismiss the alert, the focus will go back to the previous element before the alert pops up. 我检查了一些Apple应用程序,我发现在它们解除警报后,焦点将在警报弹出之前返回到上一个元素。 Any idea how to achieve this? 知道怎么做到这一点? Thanks! 谢谢!

I was having this issue earlier today - the way I solved it is by posting a UIAccessibilityScreenChangedNotification instead of a UIAccessibilityLayoutChangedNotification : 我今天早些时候遇到过这个问题 - 我解决它的方法是发布一个UIAccessibilityScreenChangedNotification而不是UIAccessibilityLayoutChangedNotification

UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, button)

Layout changes are for a change in layout in the current context of your view. 布局更改用于在视图的当前上下文中更改布局 Screen changes are for use when a change in context is experienced by the user, ie dismissing an alert and returning back to the presenting view controller. 屏幕更改用于当用户体验到上下文改变时,即解除警报并返回到呈现视图控制器。

You can get rid of the dispatch_after block, too - using the screen changed notification instead will give you the same functionality you describe from one of Apple's apps. 您也可以删除dispatch_after块 - 使用屏幕更改通知代替您将从Apple的某个应用程序中获得相同的功能。

Here is a link to an answer explaining the difference between UIAccessibilityLayoutChangedNotification and UIAccessibilityScreenChangedNotification. 是一个答案的链接,解释了UIAccessibilityLayoutChangedNotification和UIAccessibilityScreenChangedNotification之间的区别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM