Search code examples
iphoneuiaccessibility

UIAccessibility on custom slider control


I have a custom control (UIView subclass) that is identical to "slide to unlock" control on the lock screen.

Is there a way I can get notified when Voiceover has selected the view? Also, when it's selected the gesture recognizer is not receiving gestures, thus rendering the control useless.

Any tips? Thus far, I've set the isAccessibilityElement and labels/hints.


Solution

  • I had to do two things to make it work:

    self.accessibilityTraits = UIAccessibilityTraitAllowsDirectInteraction;
    

    and added a double tap gesture recognizer that only triggers when voice is running

        UITapGestureRecognizer *doubleTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(didDoubleTap:)];
        doubleTapGestureRecognizer.numberOfTapsRequired = 2;
        [self addGestureRecognizer:doubleTapGestureRecognizer];
    
    - (void)didDoubleTap:(UITapGestureRecognizer*)tapGesture {
        if(UIAccessibilityIsVoiceOverRunning()){
            [self slideHandleToFinish];
        } }