TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Feb 2015 |
Maintained by Danny Ricciotti.
Konami code gesture recognizer for iOS. The recognizer is a subclass of UIGestureRecognizer has can be used in the same way as any other recognizer. Swipe gestures correspond to the Up/Down/Left/Right parts of the sequence. An optional feature allows you to implement a custom B+A+Enter action.
Contact me via Twitter @topwobble
Add the gesture recognizer to a UIView using the following code.
#import "DRKonamiGestureRecognizer.h"
- (void)addKonami
{
konami = [[DRKonamiGestureRecognizer alloc] initWithTarget:self action:@selector(_konamiHappened:)];
[self.view addGestureRecognizer:konami];
}
- (void)_konamiHappened:(DRKonamiGestureRecognizer *)recognizer
{
// NOTE: Test the state to make sure the recognizer is finished.
if ( [recognizer konamiState] == DRKonamiGestureStateRecognized ) {
NSLog(@"Konami Code Recognized!");
}
}
Optionally, you can require the user to enter B+A+Enter in order for the gesture to be recognized. You will need to implement the DRKonamiGestureProtocol which has required methods that let your UI respond to the request for the A, B, or Enter action. If you are not using the B+A+Enter feature than you do not need to set the recognizer's delegate.
- (void)addKonami
{
konami = [[DRKonamiGestureRecognizer alloc] initWithTarget:self action:@selector(_konamiHappened:)];
[konami setKonamiDelegate:self];
[konami setRequiresABEnterToUnlock:YES];
[self.view addGestureRecognizer:konami];
}
- (void)_konamiHappened:(DRKonamiGestureRecognizer *)recognizer
{
NSLog(@"Konami Code Recognized!");
}
#pragma mark -
#pragma mark DRKonamiGestureProtocol
- (void)DRKonamiGestureRecognizerNeedsABEnterSequence:(DRKonamiGestureRecognizer*)gesture
{
/// your code here.
}
- (void)DRKonamiGestureRecognizer:(DRKonamiGestureRecognizer*)gesture didFinishNeedingABEnterSequenceWithError:(BOOL)error
{
/// your code here.
}
The DRKonamiGestureProtocol protocol is required only if you are using the B+A+Enter feature. The recognizer will inform its delegate when the B+A+Enter sequence is needed and when the sequence is no longer needed (due to gesture failing or succeeding).