Caleb Davenport has a great post on using UIKeyCommand to implement hardware keyboard shortcuts (now a broken link).
Beside its intended use, UIKeyCommand
also presents a great way for you to add debugging shortcuts — that you remove when you ship — to your app. For example, you can assign a shortcut to print out the model details of your current screen or to run -exerciseAmbiguityInLayout if you use Auto Layout.
#ifdef DEBUG
//Subclass of UIResponder
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (NSArray *)keyCommands {
return @[
[UIKeyCommand keyCommandWithInput:@"+" modifierFlags:0 action:@selector(callExerciseAmbiguityInLayoutRecursively)],
[UIKeyCommand keyCommandWithInput:@"-" modifierFlags:0 action:@selector(displayModelData)],
];
}
#endif
Your feedback is valuable: Do you want more nuggets like this? Yes or No
.