2012-11-19 22 views
11

所以我有一個UICollectionView與一組UICollectionViewCells顯示使用自定義UILayout。配音只能看到一個uicollectionview頁面

我已經配置了UILayout來佈置所有UICollectionViewCells,它們與ios上的照片應用程序中的佈局方式幾乎完全相同。

問題是,當開啓語音撥號時,用戶使用滑動遍歷UICollectionViewCells,當用戶到達頁面上最後一個可見單元格並嘗試向前滑動到下一個單元格時,它只是停止。

我知道在UITableView中,單元格將繼續向前移動,並且表格視圖將自動向下滾動。

有誰知道如何得到這種行爲?

回答

9

經過數小時的頭痛,解決方案非常簡單。如果任何人都遇到類似的問題,這是我做了什麼:

在UICollectionViewCell的子類,您正在使用您的CollectionView,覆蓋accessibilityElementDidBecomeFocused和實現它是這樣的:

- (void)accessibilityElementDidBecomeFocused 
{ 
    UICollectionView *collectionView = (UICollectionView *)self.superview; 
    [collectionView scrollToItemAtIndexPath:[collectionView indexPathForCell:self] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally|UICollectionViewScrollPositionCenteredVertically animated:NO]; 
    UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil); 
} 
1

斯蒂芬的回答工作爲了我!謝謝。

我想補充一點,這似乎隻影響iOS6;它看起來像他們在iOS7中修復它。

而且,可以使通過傳遞自我,而不是零到UIAccessibilityPostNotification稍快和更清潔的滾動 - 像這樣:

- (void)accessibilityElementDidBecomeFocused {  
    UICollectionView *collectionView = (UICollectionView *)self.superview; 
    [collectionView scrollToItemAtIndexPath:[collectionView indexPathForCell:self] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally|UICollectionViewScrollPositionCenteredVertically animated:NO]; 
    UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, self); 
} 
15

這個答案爲我工作了。謝謝!

還有一個電話你必須啓用才能使其工作。否則你的方法(void)accessibilityElementDidBecomeFocused將永遠不會被調用。您必須啓用對象Cell的可訪問性。

  1. 選項1:在ViewController中,將單元格實例設置爲具有可訪問性。

    Cell *cell = [cv dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath]; 
    [cell setIsAccessibilityElement:YES]; 
    
  2. 選項2:實現在細胞對象的輔助接口:

    - (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); 
    } 
    
0

它並沒有爲我工作,但我張貼在這裏Kgreenek &斯蒂芬的斯威夫特剛剛版如果有人想複製粘貼它,以檢查它是否可以解決他的問題。

override func accessibilityElementDidBecomeFocused() { 
    if let superview = self.superview as? UICollectionView, let indexPath = superview .indexPath(for: self) { 
      superview.scrollToItem(at: indexPath, at: [.centeredVertically, .centeredHorizontally], animated: false) 
      UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, self) 
    } 
} 
相關問題