How to have accessible swipe action for iCarousel

♀尐吖头ヾ 提交于 2019-12-10 11:58:33

问题


I am trying to make an accessible app. The problem arises when I wanted to have standard (Three-finger swipe right or left) behavior with iCarousel. Since iCarousel is not fully accessible by nature and it just lets user to have items be User intractable.

I done some research, there are some workarounds but I also don't want to implement UIAccessibilityCustomAction cause this will not give the user easy to swipe ability.


回答1:


You can override and implement accessibilityScroll(_:) method as:

extension iCarousel {
    override open func accessibilityScroll(_ direction: UIAccessibilityScrollDirection) -> Bool {
        super.accessibilityScroll(direction)

        if direction == UIAccessibilityScrollDirection.left {
            self.scroll(byOffset: 1, duration: 1.0)
        }
        if direction == UIAccessibilityScrollDirection.right {
            self.scroll(byOffset: -1, duration: 1.0)
        }
        return true
    }
}

and post a desire (e.g. page number) in iCarousel delegate method carouselDidEndScrollingAnimation, you may also change the accessibilityLabel and other accessibility related values here.

func carouselDidEndScrollingAnimation(_ carousel: iCarousel) {
    self.carousel.accessibilityLabel = accLabels[currentItemIndex]
    self.carousel.accessibilityValue = accValues[currentItemIndex]
    UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification,
                                    "item \(currentItemIndex + 1) of \(self.items.count)")
}

Also in viewDidLoad set the initial accessibilityLabel as well as:

self.carousel.accessibilityTraits = UIAccessibilityTraitUpdatesFrequently

I hope this helps someone.



来源:https://stackoverflow.com/questions/45643930/how-to-have-accessible-swipe-action-for-icarousel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!