使程序化的iOS UIView完全可访问

时间:2011-06-13 15:40:54

标签: iphone ios accessibility

我正在以编程方式为iOS构建UINavigationContoller,并且在使其完全可访问时遇到问题。在loadView中,我创建了主UIView并将其设置为无法访问:

    - (void)loadView
    {
    CGRect viewRect = [[UIScreen mainScreen] applicationFrame];
    UIView *tmp = [[UIView alloc] initWithFrame:viewRect];
    [tmp setIsAccessibilityElement:NO];

然后我添加了仅包含背景图片的其他UIViews,并将其设置为无法访问。所有视图和控件都会添加到上面创建的“tmp”UIView中。这是一个“背景”视图示例:

UIImage* microphone = [UIImage imageNamed:@"microphone.jpg"];
    UIView* microphoneView = [[[UIView alloc] initWithFrame: CGRectMake(0,0,viewRect.size.width, microphone.size.height)] autorelease];
    [microphoneView setBackgroundColor:[UIColor colorWithPatternImage:microphone]];
    [microphoneView setIsAccessibilityElement:NO];
    [tmp addSubview:microphoneView];

最后,我添加了UIButtonUILabelUIButtonBarItem。我最后添加它们,因此它们位于视图层次结构的顶部。我为它们添加了可访问性标签和特征。这是UIButton

self.recordImage = [UIImage imageNamed: @"record_button.png"];
self.stopRecordImage = [UIImage imageNamed: @"stop_button.png"];
self.recordButton.accessibilityTraits |= UIAccessibilityTraitStartsMediaSession;
self.recordButton = [[UIButton alloc  ] initWithFrame: CGRectMake((viewRect.size.width - recordImage.size.width)/2 , (microphone.size.height + (grayBkg.size.height - recordImage.size.height)/2), recordImage.size.width, recordImage.size.height)];
[self.recordButton setIsAccessibilityElement:YES];
[self.recordButton setAccessibilityLabel:  @"toggle recording start"];
[self.recordButton setImage: recordImage forState:UIControlStateNormal];
[self.recordButton addTarget: self action:@selector(processButton:) forControlEvents:UIControlEventTouchUpInside];
[tmp addSubview:recordButton];

终于

....
[self setView:tmp];
[tmp release];

我打电话给UIAccessibilityPostNotificationUIAccessibilityScreenChangedNotification,无);当我把这个视图推到堆栈上时。

启用画外音后,当显示视图时,我可以滑动并为每个元素(UIButtonBarItemUILabelUIButton)提供焦点,然后我可以使用双重激活它们挖掘。但是,VoiceOver不会提供有关元素的信息。使用辅助功能检查器在模拟器中进行测试,显示我通过aControl.accessibilityLabel = @“标签”设置的标签;

此视图用于录制音频。如果我激活按钮并录制音频并停止录音,VoiceOver现在会在我对焦时说出元素的标签?为什么VoiceOver在视图首次加载时不会说出信息?任何线索都赞赏!

我正在使用iOS 4.3.3在iPad 2上进行测试。

2 个答案:

答案 0 :(得分:2)

如果您希望无法访问自己的观点,请使用:

[microphoneView setUserInteractionEnabled:NO];  

答案 1 :(得分:1)

此视图用于录音。问题是我在viewDidLoad方法中将AVSession类别设置为AVAudioSessionCategoryRecord。这导致VoiceOver不说出视图信息。我修改了代码,只有在按下记录按钮时才将类别设置为AVAudioSessionCategoryRecord。录制完成后,我将其设置为AVAudioSessionCategoryPlayAndRecord。以下是完全解释它的主题:http://lists.apple.com/archives/accessibility-dev/2011/Jul/msg00002.html