If you're supporting iOS 9 and newer, this behavior is now the standard - no special handling required.
If you're supporting iOS 8 and lower, subclass UIPageControl
and override accessibilityIncrement
and accessibilityDecrement
. You don't need to override the accessibilityTraits
property to indicate it's adjustable - UIPageControl
is adjustable 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 for ValueChanged and respond appropriately 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 don't subclass UIPageControl
this target/action will still be called but the current page dot indicator will not update.