when VoiceOver is on, is there a way an app can detect a single-finger (left-right)swipe?

ε祈祈猫儿з 提交于 2019-12-20 03:19:52

问题


When VoiceOver is active on an iOS device, the single-finger swipe(left or right) gesture allows users to browse the different elements in the view. Is there a way to detect if a user used the single-finger swipe gesture when using voiceover?


回答1:


You might be asking either of 2 things:

  1. You want to know when the VoiceOver user successfully issued the single-finger swipe left/right gesture to VoiceOver - VoiceOver will process ("steal") the gesture from your code and do its thing (move VoiceOver cursor to the next/previous element). The closest you can get is to get notifications for a UIView when the VoiceOver cursor lands on it or leaves it (see the UIAccessibilityFocus protocol).

  2. You want to make part of your UI not subject to VoiceOver gestures (VoiceOver will not process ("steal") gestures in this area) so that you can detect the gestures yourself (including the single-finger swipe left/right) in a standard way and process them in the way you want for your app. Then you must add the UIAccessibilityTraitAllowsDirectInteraction trait to the accessibilityTraits property to the relevant UIView (see UIAccessibility protocol for more details). A prominent example of where this is used is in GarageBand for iOS - the piano keyboard or drums have this trait so that VoiceOver user can play on the instruments without turning VoiceOver off.




回答2:


I ended up creating a category/extension on UIView and overriding accessibilityElementDidBecomeFocused().

Here I can get a global hook, which gets called every time the accessibility state has changed.

Swift example:

extension UIView {

//MARK: Accessibility

    override public func accessibilityElementDidBecomeFocused() {
        super.accessibilityElementDidBecomeFocused()

        UIApplication.sharedApplication().sendEvent(UIEvent())
    }
}


来源:https://stackoverflow.com/questions/20710991/when-voiceover-is-on-is-there-a-way-an-app-can-detect-a-single-finger-left-rig

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