[英]Turning off Voice-over focus for a cell in table view and not for others
The first cell in my table view is a dummy cell and thus, when Voice-over mode is ON, I want to skip that cell so that the focus does not come to that control and thus, none of its traits are spoken by the Voice over.我的表格视图中的第一个单元格是一个虚拟单元格,因此,当画外音模式打开时,我想跳过该单元格,以便焦点不会落在该控件上,因此,语音不会说出它的任何特征超过。 I wrote the code pasted below to acheive the same, thinking that isAccessibilityElement
alone is sufficient for this.我写了下面粘贴的代码来实现相同的目的,认为仅isAccessibilityElement
就足够了。 But it seems that is not the case.但似乎并非如此。 Even though this element i said to be non-accessible in the code, still its getting focus by right/left flicks in Voice-over
mode.尽管我说这个元素在代码中是不可访问的,但它仍然通过在Voice-over
模式下向右/向左轻弹来获得焦点。 Any idea as to how this can be achieved?关于如何实现这一点的任何想法?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
....
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if(indexPath.row == 0)
{
cell.isAccessibilityElement = 0;
}
}
use some cutom cell, and within that cell definition implement this:使用一些 cutom 单元格,并在该单元格定义中实现:
- (NSInteger)accessibilityElementCount {
NSIndexPath *indexPath = [(UITableView *)self.superview indexPathForCell: self];
if(indexPath.row==0){
return 0;
}
else{
return 1;
}
}
The current way to do this seems to be setting accessibilityElementsHidden
on the cell to true
/ YES
(depending on whether using Swift or Obj-C.当前执行此操作的方法似乎是将单元格上的accessibilityElementsHidden
设置为true
/ YES
(取决于是使用 Swift 还是 Obj-C。
Seems cleaner than other answers proposed and seems effective in my very brief testing.似乎比提出的其他答案更清晰,并且在我非常简短的测试中似乎很有效。
Just override the cell's function accessibilityElementCount
like this:只需像这样覆盖单元格的功能accessibilityElementCount
:
Swift 4.2:斯威夫特 4.2:
override func accessibilityElementCount() -> Int {
return 0
}
It's not ideal but could you only display the cell when VoiceOver is not activated?这并不理想,但您能否仅在 VoiceOver 未激活时显示单元格? You can use the您可以使用
UIAccessibilityIsVoiceOverRunning()
Function to see if VoiceOver is on when your app loads, and register the在您的应用程序加载时查看 VoiceOver 是否打开的功能,并注册
@selector(voiceOverStatusChanged)
Notification so you can be informed if the user enables or disables voiceover.通知,以便您在用户启用或禁用画外音时收到通知。 For more on this see the following blog post.有关这方面的更多信息,请参阅以下博客文章。 < http://useyourloaf.com/blog/2012/05/14/detecting-voiceover-status-changes.html > < http://useyourloaf.com/blog/2012/05/14/detecting-voiceover-status-changes.html >
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.