Skip to content

Instantly share code, notes, and snippets.

@dblock
Created March 24, 2014 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dblock/9732650 to your computer and use it in GitHub Desktop.
Save dblock/9732650 to your computer and use it in GitHub Desktop.
ASCII Art + Konami Code Easter Egg for iOS
//
// 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
//
// 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
#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