voice over can only see a page of a uicollectionview

前端 未结 4 420
忘了有多久
忘了有多久 2020-12-13 21:26

So i have a UICollectionView with a set of UICollectionViewCells displayed using a custom UILayout.

I\'ve configured the UILayout to lay out all the UICollectionView

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-13 22:14

    This answer worked for me, too. Thanks!

    There is one other call you must have enabled to get this to work. Otherwise your method (void)accessibilityElementDidBecomeFocused will never get called. You must enable accessibility on the object Cell.

    1. Option 1: In ViewController, set the cell instance to have accessibility.

      Cell *cell = [cv dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath];
      [cell setIsAccessibilityElement:YES];
      
    2. Option 2: Implement the accessibility interface in the cell object:

      - (BOOL)isAccessibilityElement
      {
          return YES;
      }
      
      - (NSString *)accessibilityLabel {
          return self.label.text;
      }
      
      - (UIAccessibilityTraits)accessibilityTraits {
          return UIAccessibilityTraitStaticText;  // Or some other trait that fits better
      }
      
      - (void)accessibilityElementDidBecomeFocused
      {
          UICollectionView *collectionView = (UICollectionView *)self.superview;
          [collectionView scrollToItemAtIndexPath:[collectionView indexPathForCell:self] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally|UICollectionViewScrollPositionCenteredVertically animated:NO];
          UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, self);
      }
      

提交回复
热议问题