ios - 呈现 View 时,VoiceOver 不会始终关注 UILabel

标签 ios objective-c swift accessibility uiaccessibility

我们有一个登录屏幕,其中最初隐藏了一个 UILabel 以表示用户注销应用程序时的消息。

当在 iOS 中打开 VoiceOver 并且用户尝试从应用程序注销时,画外音最好读出注销消息标签。相反,它会读出登录屏幕的密码文本字段。

注销按钮的 Action 有以下实现代码。

let loginStoryboard = UIStoryboard(name: "Login", bundle: nil)
        let loginViewController = loginStoryboard.instantiateInitialViewController() as! LoginViewController
        loginViewController.modalPresentationStyle = UIModalPresentationStyle.CurrentContext
loginViewController.logOut = true
self.presentViewController(loginViewController, animated: true, completion:nil)

注销指示器设置为显示注销消息标签。 LoginViewController viewDidLoad 代码。

if(!logOut){
            self.logOutMsg.hidden = true
}else{
            self.logOutMsg.text = NSLocalizedString("LoggedOutMsg", comment: "Logged out message")
            self.logOutMsg.hidden = false
}

登录屏幕字段在 Storyboard中启用了辅助功能。

行为不一致:有时会读取注销消息标签,有时会读取密码文本字段。 每当 VoiceOver 读取密码文本字段时,我都会在控制台日志中看到错误。

 |error| Could not find <UIWindow: 0x124d13b10; frame = (0 0; 768 1024); gestureRecognizers = <NSArray: 0x174241140>; layer = <UIWindowLayer: 0x1742319c0>> in a list of sorted view [parent: <CaseworkerApp.AppDelegate: 0x124e008e0>] siblings (
        "<UILabel: 0x124d06cf0; frame = (132 1; 300 18); text = 'You are logged out of IBM...'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x1742921b0>>",
        "<CaseworkerApp.LoginTextField: 0x124da4890; baseClass = UITextField; frame = (80 37; 330 50); text = ''; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x1704551e0>; layer = <CALayer: 0x175033de0>>",
        "<CaseworkerApp.LoginTextField: 0x124d9bd50; baseClass = UITextField; frame = (80 110; 330 50); text = ''; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; tag = 1; gestureRecognizers = <NSArray: 0x17044dfb0>; layer = <CALayer: 0x175227ce0>>",
        "<UIButton: 0x124d52900; frame = (80 183; 330 50); autoresize = RM+BM; layer = <CALayer: 0x175039ae0>>"
    ).  If this happened right around a screen change, it might be okay, but otherwise this is probably a bug.
    2015-08-10 16:46:50.108 CaseworkerApp[2217:479225] |error| Could not find <UIWindow: 0x124d13b10; frame = (0 0; 768 1024); gestureRecognizers = <NSArray: 0x174241140>; layer = <UIWindowLayer: 0x1742319c0>> in a list of sorted view [parent: <CaseworkerApp.AppDelegate: 0x124e008e0>] siblings (
        "<UILabel: 0x124d06cf0; frame = (132 1; 300 18); text = 'You are logged out of IBM...'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x1742921b0>>",
        "<CaseworkerApp.LoginTextField: 0x124da4890; baseClass = UITextField; frame = (80 37; 330 50); text = ''; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x1704551e0>; layer = <CALayer: 0x175033de0>>",
        "<CaseworkerApp.LoginTextField: 0x124d9bd50; baseClass = UITextField; frame = (80 110; 330 50); text = ''; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; tag = 1; gestureRecognizers = <NSArray: 0x17044dfb0>; layer = <CALayer: 0x175227ce0>>",
        "<UIButton: 0x124d52900; frame = (80 183; 330 50); autoresize = RM+BM; layer = <CALayer: 0x175039ae0>>"
    ).  

如果这发生在屏幕更改前后,可能没问题,否则这可能是一个错误。

请帮忙解决这个问题?

最佳答案

呈现 View 时,VoiceOver 从辅助功能树中的第一个元素开始读取。可能有两种解决方案。

首先,您可以修改订单。

Change order of read items with VoiceOver

其次,您可以通过从 UIAccessibility 发布 ScreenChanged Notification 指示 VoiceOver 应该关注哪个元素,从而使 VoiceOver 在 View 更改时关注特定元素。

UIAccessibility.post(notification:.screenChanged, argument:elementToBeFocussed)

从文档中阅读更多信息。

UIAccessibility.post: https://developer.apple.com/documentation/uikit/uiaccessibility/1615194-post

UIAccessibility.Notification:https://developer.apple.com/documentation/uikit/uiaccessibility/notification

屏幕已更改:https://developer.apple.com/documentation/uikit/uiaccessibility/notification/1620198-screenchanged

关于ios - 呈现 View 时,VoiceOver 不会始终关注 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31918557/

相关文章:

Ios UIImageController 委托(delegate)未声明的错误

ios - 一段时间后 AVAssetWriterInputPixelBufferAdaptor pixelBufferPool 变为 NULL

iphone - iOS UIButton 始终是透明的

objective-c - 如何在 iOS 中加载 XIB

ios - Swift:通过 Facebook 应用捕获 Facebook 登录事件

ios - 使用谓词过滤字典数组

objective-c - Apple Script Bridge 的奇怪错误 - iTunes

ios - 当我快速滚动表格时,未调用 cellForRowAtIndexpath 方法

ios - 我一直遇到错误实例成员 'object' 不能用于类型 ___

swift - 如何在 SwiftUI for MacOS 中创建多行文本字段?