Created
March 24, 2014 01:28
-
-
Save dblock/9732650 to your computer and use it in GitHub Desktop.
ASCII Art + Konami Code Easter Egg for iOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ARKonamiKeyboardView.h | |
// Artsy | |
// | |
// Created by Daniel Doubrovkine on 3/21/14. | |
// Copyright (c) 2014 Art.sy. All rights reserved. | |
// | |
#import <DRKonamiCode/DRKonamiGestureRecognizer.h> | |
@interface ARKonamiKeyboardView : UIView <UIKeyInput> | |
- (id)initWithKonamiGestureRecognizer:(DRKonamiGestureRecognizer *)gestureRecognizer; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ARKonamiKeyboardView.m | |
// Artsy | |
// | |
// Created by Daniel Doubrovkine on 3/21/14. | |
// Copyright (c) 2014 Art.sy. All rights reserved. | |
// | |
#import "ARKonamiKeyboardView.h" | |
#import <DRKonamiCode/DRKonamiGestureRecognizer.h> | |
@interface ARKonamiKeyboardView () | |
@property (nonatomic, strong) DRKonamiGestureRecognizer *gestureRecognizer; | |
@end | |
@implementation ARKonamiKeyboardView | |
- (id)initWithKonamiGestureRecognizer:(DRKonamiGestureRecognizer *)gestureRecognizer | |
{ | |
self = [super init]; | |
if (self) { | |
_gestureRecognizer = gestureRecognizer; | |
} | |
return self; | |
} | |
- (void)insertText:(NSString *)text { | |
if ([text.lowercaseString isEqualToString:@"b"]) { | |
[self.gestureRecognizer BButtonAction]; | |
} else if ([text.lowercaseString isEqualToString:@"a"]) { | |
[self.gestureRecognizer AButtonAction]; | |
[self.gestureRecognizer enterButtonAction]; | |
} else { | |
[self.gestureRecognizer enterButtonAction]; | |
} | |
} | |
- (BOOL)canBecomeFirstResponder { | |
return YES; | |
} | |
- (void)deleteBackward { | |
} | |
- (BOOL)hasText { | |
return YES; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <DRKonamiCode/DRKonamiGestureRecognizer.h> | |
#import "ARKonamiKeyboardView.h" | |
#import <ARASCIISwizzle/UIFont+ASCII.h> | |
#import <ARASCIISwizzle/UIImageView+ASCII.h> | |
@interface SampleViewController() <DRKonamiGestureProtocol> | |
@property (nonatomic, readonly) ARKonamiKeyboardView *konamiKeyboardView; | |
@end | |
(void)viewWillAppear:(BOOL)animated | |
{ | |
[super viewWillAppear:animated]; | |
[self addKonami]; | |
} | |
- (void)konami:(DRKonamiGestureRecognizer *)recognizer | |
{ | |
if ([recognizer konamiState] == DRKonamiGestureStateRecognized ) { | |
UIFont.ascii = ! UIFont.ascii; | |
UIImageView.ascii = ! UIImageView.ascii; | |
// TODO: reload current view | |
} | |
} | |
- (void)addKonami | |
{ | |
DRKonamiGestureRecognizer *konamiGestureRecognizer = [[DRKonamiGestureRecognizer alloc] initWithTarget:self action:@selector(konami:)]; | |
_konamiKeyboardView = [[ARKonamiKeyboardView alloc] initWithKonamiGestureRecognizer:konamiGestureRecognizer]; | |
[konamiGestureRecognizer setKonamiDelegate:self]; | |
[konamiGestureRecognizer setRequiresABEnterToUnlock:YES]; | |
[self.view addGestureRecognizer:konamiGestureRecognizer]; | |
} | |
#pragma mark - | |
#pragma mark DRKonamiGestureProtocol | |
- (void)DRKonamiGestureRecognizerNeedsABEnterSequence:(DRKonamiGestureRecognizer*)gesture | |
{ | |
[self.view addSubview:self.konamiKeyboardView]; | |
[self.konamiKeyboardView becomeFirstResponder]; | |
} | |
- (void)DRKonamiGestureRecognizer:(DRKonamiGestureRecognizer*)gesture didFinishNeedingABEnterSequenceWithError:(BOOL)error | |
{ | |
[self.konamiKeyboardView resignFirstResponder]; | |
[self.konamiKeyboardView removeFromSuperview]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment