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

时间:2015-08-10 11:38:10

标签: ios objective-c swift accessibility uiaccessibility

我们有一个最初隐藏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)

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

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

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

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

如果在屏幕更改时发生这种情况,可能没问题,但否则这可能是一个错误。

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

1 个答案:

答案 0 :(得分:0)

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

首先,您可以修改订单。

Change order of read items with VoiceOver

第二,您可以通过从UIAccessibility中发布ScreenChanged通知(指示VoiceOver应该关注哪个元素)来使VoiceOver在视图更改时将焦点放在特定元素上。

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

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