How do you exclude a UIButton from VoiceOver?

瘦欲@ 提交于 2020-01-02 02:19:12

问题


I have a UIButton that is sometimes blank (no text or image). When it is blank, I want VoiceOver to skip over it. I've tried the following things, but none of them do the job -- the button still gets highlighted as the user swipes through the views:

  • Set the button and all of its subviews' .accessibilityTraits to UIAcessibilityTraitNotEnabled. This prevents VoiceOver from saying anything when the button is selected, but it still allows the button to be selectable by VoiceOver.

  • Disable the button (I verified that the button is disabled in the Debug View Hierarchy view). The button remains selectable by VoiceOver.

Anybody know how to make VoiceOver skip over / ignore a UIButton completely?


回答1:


Try the following:

someButton.isAccessibilityElement = NO;

This tells the button that it isn't an accessible element. This should prevent voice-over from stopping at the button.




回答2:


Swift 4

This didn't work for me:

someButton.isAccessibilityElement = false 

This did work:

someButton.accessibilityElementsHidden = true


来源:https://stackoverflow.com/questions/28093711/how-do-you-exclude-a-uibutton-from-voiceover

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!