2012-11-19 27 views
11

Vì vậy, tôi có UICollectionView với một tập hợp UICollectionViewCells được hiển thị bằng UILayout tùy chỉnh.thoại qua chỉ có thể xem một trang của chế độ xem trước

Tôi đã định cấu hình UILayout để sắp xếp tất cả UICollectionViewCells gần như giống hệt cách chúng được trình bày trong ứng dụng ảnh trên ios.

Vấn đề là, có vẻ như khi giọng nói được bật và người dùng di chuyển qua UICollectionViewCells bằng cách vuốt, khi người dùng đến ô hiển thị cuối cùng trên trang và cố vuốt sang ô kế tiếp , nó chỉ dừng lại.

Tôi biết rằng trong UITableXem các ô sẽ tiếp tục di chuyển về phía trước và chế độ xem bảng sẽ tự động cuộn xuống.

Có ai biết cách nhận hành vi này không?

Trả lời

9

Sau giờ và giờ đau đầu, giải pháp thực sự đơn giản. Nếu bất cứ ai khác đi qua một vấn đề tương tự, đây là những gì tôi đã làm:

Trong lớp con của UICollectionViewCell mà bạn đang sử dụng cho CollectionView của bạn, ghi đè accessibilityElementDidBecomeFocused và thực hiện nó như thế này:

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

câu trả lời Stephen làm việc cho tôi! Cảm ơn.

Tôi muốn thêm rằng điều này dường như chỉ ảnh hưởng đến iOS6; có vẻ như họ đã sửa nó trong iOS7.

Ngoài ra, bạn có thể làm cho di chuyển hơi nhanh hơn và sạch hơn bằng cách tự thay vì con số không để UIAccessibilityPostNotification - như vậy:

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

Câu trả lời này làm việc cho tôi, quá. Cảm ơn!

Có một cuộc gọi khác mà bạn phải bật để thực hiện điều này. Nếu không, phương thức của bạn (void) accessibilityElementDidBecomeFocused sẽ không bao giờ được gọi. Bạn phải bật trợ năng trên đối tượng Cell.

  1. Tùy chọn 1: Trong ViewController, hãy đặt thể hiện ô để có trợ năng.

    Cell *cell = [cv dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath]; 
    [cell setIsAccessibilityElement:YES]; 
    
  2. Phương án 2: Thực hiện giao diện khả năng tiếp cận trong đối tượng di động:

    - (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

Nó không làm việc cho tôi, nhưng tôi gửi ở đây phiên bản Swift của Kgreenek & Stephen chỉ trong trường hợp ai đó muốn sao chép dán nó một cách nhanh chóng để kiểm tra xem nó có giải quyết được vấn đề của mình hay không.

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) 
    } 
} 
Các vấn đề liên quan