percivalwcy
percivalwcy

Reputation: 51

Override UIAccessibilityLayoutChangedNotification when UICollectionView changes layout

I'm trying to enable VoiceOver accessibility on my collection view which behaves as follows:

  1. Upon selection of an item, it will remove the rest of the items in the section, leaving only the item that was selected.
  2. When I select the item again, it will re-populate the section with the items that was previously removed.

For step 1, voiceover reads out the item just fine, and it'll be the focus after the layout change.

However, for step 2, things get a bit weird. It'll start reading out the item, and just before it finishes, the focus jumps to another item, and begins reading that one instead.

From Apple's documentation about collection views, it automatically posts a layout change notification when a layout occurs. But, from the looks of it, it's passing on some random element to the first focus element after the layout change.

When a collection view changes its onscreen layout, it posts the UIAccessibilityLayoutChangedNotification notification.

Is there anyway to override this automatic layout changed notification, so that I can pass in the correct focus element?

Upvotes: 1

Views: 958

Answers (1)

percivalwcy
percivalwcy

Reputation: 51

I found the reason for what was happening. The reason an element was randomly focusing was because I was calling reloadData on the collectionview in the performBatchUpdate's completion block. Removing the reloadData solved this problem. However, because I'm not calling reloadData, I had to call reloadItemsAtIndexPaths on specific cells, which is fine in my case.

Upvotes: 1

Related Questions