UIPageControl and VoiceOver / Availability

When using the voice jump on the springboard, when UIPageControl is selected at the bottom of the screen, VoiceOver announces something like โ€œPage 1 of 5. Adjustableโ€. and the user can scroll up and down to change pages.

In my application, I do not get the โ€œadjustableโ€ part, and the pages cannot be changed by scrolling.

Any ideas how I can fix this? This clearly kills the usability of the application.

+8
source share
3 answers

I subclassed the UIPageControl and overridden the -accessibilityTraits getter to return the UIAccessibilityTraitAdjustable , getting Voice Over to read "custom."

To add actions: implement the -accessibilityIncrement and -accessibilityDecrement methods specified in the UIAccessibilityAction category.

Since my pages respond to UIControlEventValueChanged events, I am also required to send actions for this event.

Code example

 @interface AccessibleUIPageControl : UIPageControl @end @implementation AccessibleUIPageControl - (UIAccessibilityTraits)accessibilityTraits { return super.accessibilityTraits | UIAccessibilityTraitAdjustable; } - (void)accessibilityIncrement { self.currentPage = self.currentPage + 1; [self sendActionsForControlEvents:UIControlEventValueChanged]; } - (void)accessibilityDecrement { self.currentPage = self.currentPage - 1; [self sendActionsForControlEvents:UIControlEventValueChanged]; } @end 
+8
source

If you support iOS 9 and later, this behavior is now standard - no special processing is required.

If you support iOS 8 and below, subclass UIPageControl and override accessibilityIncrement and accessibilityDecrement . You do not need to override the accessibilityTraits property to specify it as customizable - UIPageControl configured by default.

 import UIKit class AccessibleUIPageControl: UIPageControl { override func accessibilityIncrement() { self.currentPage += 1 self.sendActionsForControlEvents(.ValueChanged) } override func accessibilityDecrement() { self.currentPage -= 1 self.sendActionsForControlEvents(.ValueChanged) } } 

Then in your view controller, you can listen to ValueChanged and respond accordingly to show the content for the new page:

 //viewDidLoad: self.pageControl.addTarget(self, action: "didChangePage", forControlEvents: .ValueChanged) func didChangePage() { let contentOffset: CGFloat = collectionView.frame.size.width * CGFloat(pageControl.currentPage) collectionView.setContentOffset(CGPointMake(contentOffset, 0), animated: false) } 

Note that if you are not a subclass of UIPageControl , this target / action will still be called, but the current page point indicator will not be updated.

+4
source

I still needed to implement Custom AccessiblePageControl using iOS 10+ (as suggested above). I followed the approach described above, but linked IBAction on my storyboard for both touchUpInside and valueChanged.

0
source

All Articles