当呈现视图时,VoiceOver不会始终关注UILabel

Sur*_*iah 6 accessibility objective-c ios uiaccessibility swift

我们有一个UILabel隐藏的登录屏幕,最初用于表示用户退出应用程序时的消息.

当在iOS中打开VoiceOver并且用户尝试从应用程序注销时,理想情况下应该读出注销消息标签.相反,它会读出登录屏幕的密码文本字段.

注销按钮的操作具有以下实现代码.

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)
Run Code Online (Sandbox Code Playgroud)

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

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

登录屏幕字段是故事板中启用的辅助功能.

行为不一致:有时会读取注销消息标签,有时会读出密码文本字段.每当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>>"
    ).  
Run Code Online (Sandbox Code Playgroud)

如果这发生在屏幕更改周围,它可能没问题,但否则这可能是一个错误.

有任何帮助请解决此问题?

jl3*_*303 1

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

首先,您可以修改订单。

使用 VoiceOver 更改阅读项目的顺序

其次,您可以通过从 UIAccessibility 发布 ScreenChanged 通知来指示 VoiceOver 应聚焦哪个元素,从而在视图更改时使 VoiceOver 聚焦于特定元素。

UIAccessibility.post(notification:.screenChanged, argument:elementToBeFocussed)
Run Code Online (Sandbox Code Playgroud)

从文档中阅读更多信息。

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

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

screenChanged: https: //developer.apple.com/documentation/uikit/uiaccessibility/notification/1620198-screenchanged