3

I am creating a game specifically designed to be played using Switch access. The game builds a grid of buttons dynamically based on the level to mimic the grid layout of an iPad's icons. With the nature of switch access I cannot have a back button to return to the main menu as this will get counted within the game as a button and included in the tabbing through the user will be doing.

Ideally I would like the user to be able to return to the main menu on a long press of one of the switch buttons, I have tried attaching a Long press gesture recogniser onto the view that the buttons were drawn to, this worked fine in the simulator but not with the switch access button press, I then tried to attach it to each button, again this worked in the simulator but not in actual testing.

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

Adding UILongPressGestureRecognizer to the button.

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

Method called on 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 the switch access controls work just like a bluetooth keyboard (which is how I am testing at the moment). When setting up the switch access buttons I map each one to a certain keyboard key.

Does anyone know how I can get this working? I had considered disabling a button while the game is in play and re-enabling it between levels but then the user doesn't have the option to return the main menu mid game if they wish, which I feel would be bad design.

Thanks for any help.

arhkfp
  • 31
  • 2

1 Answers1

2

In scanning mode, Switch Control sequentially focuses elements. Selecting an element using a switch press activates it. However, various user settings govern the speed and criteria for selection. Your app can only respond to UI and accessibility events– there's nothing you can or, in most cases, should do to to infer the behaviors that generated these events.

Adding a custom action

If you would like to offer an action unique to users of assistive technologies, implement -accessibilityCustomActions. This allows users to choose from a set of application-defined actions in addition to the system-standard activate action.

Code

For example, to expose and respond to a custom action foo on an otherwise bare UIView, one can 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 code above with Switch Control enabled, you see a menu item for the new action:

An empty, grey view highlighted by the blue cursor of Switch Control. A menu is visible with the options "Tap" and "FooAction"

Edit:

In the comments, you ask how this could be implemented without a menu since it requires additional switch presses to access, which affects gameplay. There is another approach. You can display a menu button that is explicitly marked not accessible (isAccessibilityElement = NO). This button will not be in the scan order, but Switch Control users can still tap it by point scanning with the "Gliding Cursor" instead of item scanning. As usual, I would discourage doing something non-standard like that unless you're absolutely certain of your users' abilities.

Justin
  • 20,509
  • 6
  • 47
  • 58
  • 1
    Ah yes, of course - A individual using a leaf switch for example would never be able to register a long press, how silly of me. If someone is playing my game with one switch the switch will be set up to register as a simple tap with no menu so I won't be able to use the custom action as you suggested. Is there any other way I can offer a mean for the user to return to the main menu when playing the game? Thanks a lot for your help. – arhkfp Aug 06 '15 at 10:27
  • @kfp_arh I've made an edit to include an alternative approach. – Justin Aug 06 '15 at 23:21
  • Thanks very much for your advice and input, I will play around with a few things and look for some feedback from my users'. – arhkfp Aug 07 '15 at 09:18