【问题标题】:UIAccessibility VoiceOver announces wrong page number for UIScrollViewUIAccessibility VoiceOver 宣布 UIScrollView 的页码错误
【发布时间】:2012-07-25 15:24:38
【问题描述】:

我正在尝试使现有应用尽可能方便地进行配音。

目前,我有一个 uiviewcontroller,它基本上是一个分页照片视图,在 uiscrollView (tourScrollView) 下方有一个 uipagecontrol,指示当前正在查看的图像/页面。

这是计算当前页面的代码:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    CGFloat pageWidth = scrollView.frame.size.width;
    self.tourScrollView.isAccessibilityElement = NO;
    scrollView.isAccessibilityElement = NO;
    int currentPage = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    pageControl.currentPage = currentPage;
}

页面计算代码完美运行。

总共显示了 5 张图片。

启用语音后,当滚动视图滚动时,而不是滚动

page 1 of 5
page 2 of 5
page 3 of 5
page 4 of 5
page 5 of 5

事情是这样的。

page 1 of 6
page 2 of 6
page 3 of 6
page 5 of 6
page 6 of 6

这是将图像添加到滚动视图的代码

-(void)addImagesToScrollview{

    NSArray *welcomeImages = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"img-01.png"],
                              [UIImage imageNamed:@"img-02.png"],
                              [UIImage imageNamed:@"img-03.png"],
                              [UIImage imageNamed:@"img-04.png"],
                              [UIImage imageNamed:@"img-05.png"],nil];

    CGRect scrollViewFrame = tourScrollView.frame;
    CGFloat scrollViewWidth = scrollViewFrame.size.width;
    CGFloat scrollViewHeight = scrollViewFrame.size.height;
    CGFloat imageX;
    for (int i = 0; i<[welcomeImages count]; i++) {

        int index = i;
        imageX = (scrollViewWidth*index) + (scrollViewWidth - IMAGE_WIDTH)/2.0;

        CGRect boarderViewRect = CGRectMake(imageX, 20.0f, IMAGE_WIDTH, IMAGE_HEIGHT);

        UIView *whiteBorderView = [[UIView alloc] initWithFrame:boarderViewRect];
        whiteBorderView.backgroundColor = [UIColor whiteColor];

        UIImageView *imageView = [[UIImageView alloc]initWithImage:[welcomeImages objectAtIndex:i]];
        CGRect imageRect = CGRectInset(boarderViewRect, IMAGE_INSET, IMAGE_INSET);
        imageView.frame = imageRect;

        CGRect descriptionRect = CGRectMake((scrollViewWidth*index) + 20.0f, imageRect.origin.y + imageRect.size.height+10, 280, 90);
        CGSize maximumLabelSize = CGSizeMake(descriptionRect.size.width,120);
        descriptionRect.size = [[self descriptionForIndex:i] sizeWithFont:[UIFont systemFontOfSize:16.0] constrainedToSize:maximumLabelSize lineBreakMode:UILineBreakModeTailTruncation];
        UILabel *imageDescription = [[UILabel alloc] initWithFrame:descriptionRect];
        imageDescription.text = [NSString stringWithFormat:@"%@",[self descriptionForIndex:i]];
        imageDescription.numberOfLines = 0;
        imageDescription.backgroundColor = [UIColor clearColor];
        imageDescription.font = [UIFont systemFontOfSize:16.0];
        imageDescription.textColor = [UIColor colorWithRed:(119.0/255.0) green:(119.0/255.0) blue:(119.0/255.0) alpha:1.0];
        imageDescription.textAlignment = UITextAlignmentCenter;
        imageDescription.shadowColor = [UIColor whiteColor];
        imageDescription.shadowOffset = CGSizeMake(0,1);

        [tourScrollView addSubview:whiteBorderView];
        [tourScrollView addSubview:imageView];
        [tourScrollView addSubview:imageDescription];

        if (i == [welcomeImages count]-1) {
            tourScrollView.contentSize = CGSizeMake(imageView.frame.origin.x + scrollViewWidth -((scrollViewWidth - IMAGE_WIDTH)/2.0), scrollViewHeight); 
        }
    }
}

如果有人指出我正确的方向,让我说出正确的页码,我将不胜感激。

更新:启用/禁用 pagingEnabled 没有区别。我认为 VoiceOver 会覆盖我根据滚动视图大小所做的分页计算。

【问题讨论】:

  • 很难想象这里发生了什么。也许是视频/图片?
  • 那种耐克燃料演练pttrns.com/walkthroughs这就是我所拥有的。只是在刷卡时,画外音打开,画外音女士宣布错误的页面

标签: iphone objective-c uiscrollview accessibility voiceover


【解决方案1】:

这是修复它的原因:

去掉了注释代码,在for循环外加了一行内容大小

-(void)addImagesToScrollview{

NSArray *welcomeImages = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"img-01-welcome.png"],
                          [UIImage imageNamed:@"img-02-welcome.png"],
                          [UIImage imageNamed:@"img-03-welcome.png"],
                          [UIImage imageNamed:@"img-04-welcome.png"],
                          [UIImage imageNamed:@"img-05-welcome.png"],nil];

CGRect scrollViewFrame = tourScrollView.frame;
CGFloat scrollViewWidth = scrollViewFrame.size.width;
CGFloat scrollViewHeight = scrollViewFrame.size.height;
CGFloat imageX;
for (int i = 0; i<[welcomeImages count]; i++) {

    int index = i;
    imageX = (scrollViewWidth*index) + (scrollViewWidth - IMAGE_WIDTH)/2.0;

    CGRect boarderViewRect = CGRectMake(imageX, 20.0f, IMAGE_WIDTH, IMAGE_HEIGHT);

    UIView *whiteBorderView = [[UIView alloc] initWithFrame:boarderViewRect];
    whiteBorderView.backgroundColor = [UIColor whiteColor];

    UIImageView *imageView = [[UIImageView alloc]initWithImage:[welcomeImages objectAtIndex:i]];
    CGRect imageRect = CGRectInset(boarderViewRect, IMAGE_INSET, IMAGE_INSET);
    imageView.frame = imageRect;

    CGRect descriptionRect = CGRectMake((scrollViewWidth*index) + 20.0f, imageRect.origin.y + imageRect.size.height+10, 280, 90);
    CGSize maximumLabelSize = CGSizeMake(descriptionRect.size.width,120);
    descriptionRect.size = [[self descriptionForIndex:i] sizeWithFont:[UIFont systemFontOfSize:16.0] constrainedToSize:maximumLabelSize lineBreakMode:UILineBreakModeTailTruncation];
    UILabel *imageDescription = [[UILabel alloc] initWithFrame:descriptionRect];
    imageDescription.text = [NSString stringWithFormat:@"%@",[self descriptionForIndex:i]];
    imageDescription.numberOfLines = 0;
    imageDescription.backgroundColor = [UIColor clearColor];
    imageDescription.font = [UIFont systemFontOfSize:16.0];
    imageDescription.textColor = [UIColor colorWithRed:(119.0/255.0) green:(119.0/255.0) blue:(119.0/255.0) alpha:1.0];
    imageDescription.textAlignment = UITextAlignmentCenter;
    imageDescription.shadowColor = [UIColor whiteColor];
    imageDescription.shadowOffset = CGSizeMake(0,1);

    [tourScrollView addSubview:whiteBorderView];
    [tourScrollView addSubview:imageView];
    [tourScrollView addSubview:imageDescription];

//        if (i == [welcomeImages count]-1) {
//            tourScrollView.contentSize = CGSizeMake(imageView.frame.origin.x + scrollViewWidth -((scrollViewWidth - IMAGE_WIDTH)/2.0), scrollViewHeight); 
//        }
    }
    tourScrollView.contentSize = CGSizeMake(320.0*[welcomeImages count], scrollViewHeight);
}

我仍然不确定为什么 VO 会弄乱页码。修复前后的滚动视图行为仍然相同(弹跳和分页工作相同)。

如果我了解更多有关此问题的信息,将更新答案。

【讨论】:

    【解决方案2】:

    一个简单的选择是使您的UIScrollViewDelegate 符合UIScrollViewAccessibilityDelegate 并返回所需的字符串。

    例如:

    extension MyScrollViewDelegate: UIScrollViewAccessibilityDelegate {
        func accessibilityScrollStatus(for scrollView: UIScrollView) -> String? {
            "\(self.currentPage) of \(self.pageCount)"
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多