Return to the main menu by long pressing the "Access to the switch" button

I am creating a game specifically designed to be played using Toggle Access . The game dynamically builds a grid of buttons based on a level that mimics the layout of the iPad's grid of icons. With the nature of commutator access, I cannot have a back button to return to the main menu, as this will be counted internally as a button and tabbed through the user.

Ideally I would like the user to be able to return to the main menu when long pressing one of the toggle buttons, I tried to hook up a long press gesture recognizer to the view the buttons were drawn on, this worked fine in the simulator, but not with the toggle access button click, I then tried to attach it to each button, again this worked in the simulator but not in real testing.

Here is the code I am using that works in the simulator.

Adding a UILongPressGestureRecognizer button to a button.

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(UILongPressBack:)];
        [self.button addGestureRecognizer:longPress];

      

The method called longpress.

- (IBAction)UILongPressBack:(UILongPressGestureRecognizer*)sender {
       if (sender.state == UIGestureRecognizerStateEnded) {
       MainViewController * mainPage = [[MainViewController alloc]init];
       [self presentViewController:mainPage animated:YES completion:nil];       
       }
 }  

      

From what I understand, switch access control works the same as bluetooth keyboard (which is how I am testing at the moment). When configuring the switch access buttons, I map each to a specific keyboard key.

Does anyone know how I can get this to work? I thought about disabling the button while the game is in play and re-enabling it between levels, but then there is no way for the user to return the main menu in the middle of the game if they wish, which I consider to be bad design.

Thanks for any help.

+3


source to share


1 answer


In scan mode, Control Control focuses items sequentially. Selecting an item by pressing a radio button will activate it. However, various user settings determine the speed and selection criteria. Your application can only respond to user interface and accessibility events — there is nothing you can, or in most cases, have to do to infer the behavior that generated these events.

Adding a custom action

If you want to offer a unique action to assistive technology users, do -accessibilityCustomActions

. This allows users to choose from a set of user-defined actions in addition to activating the system standard.

code

For example, to expose and respond to a custom action foo

otherwise UIView

, one could implement:

- (BOOL)isAccessibilityElement
{
    return YES;
}

- (NSArray *)accessibilityCustomActions
{
    UIAccessibilityCustomAction *fooAction = [[UIAccessibilityCustomAction alloc] initWithName:@"FooAction" target:self selector:@selector(foo)];
    return @[fooAction];
}

- (void)foo
{
    NSLog(@"foo");
}

      



Output

Running the above code with the switch control enabled, you see the menu item for the new action:

Empty gray image highlighted with blue cursor in radio button control.  options

Edit:

In the comments, you ask how this can be implemented without a menu, as access requires an additional press of a switch, which affects the gameplay. There is another approach. You can display a menu button that is explicitly marked as unavailable ( isAccessibilityElement = NO

). This button will not be in the scan order, but Control Control users can still press it by scanning a point with the Sliding Cursor instead of scanning objects. As usual, I would discourage you from doing anything non-standard, unless you are confident in your users' abilities.

+2


source







All Articles