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

前端 未结 2 1923
不知归路
不知归路 2021-01-22 23:32

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

相关标签:
2条回答
  • 2021-01-22 23:54

    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.

    0 讨论(0)
  • 2021-01-23 00:15

    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())
        }
    }
    
    0 讨论(0)
提交回复
热议问题