DRKonamiCode 1.1.1

DRKonamiCode 1.1.1

测试测试
语言语言 Obj-CObjective C
许可证 MIT
发布最新发布2015年2月

Danny Ricciotti 维护。



  • Danny Ricciotti

DRKonamiCode

为 iOS 提供的 Konami 代码手势识别器。识别器是 UIGestureRecognizer 的子类,可以像任何其他识别器一样使用。滑动手势对应于序列的上/下/左/右部分。一个可选功能允许您实现自定义 B+A+Enter 操作。

通过 Twitter 联系我 @topwobble

在您的应用程序中使用 DRKonamiCode

使用以下代码将手势识别器添加到 UIView 中。

#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!");
    }
}

B+A+解锁(可选)

可选地,您可以让用户输入 B+A+Enter 以识别该手势。您需要实现 DRKonamiGestureProtocol,它具有必要的方法,允许您的 UI 对 A、B 或 Enter 行为的请求做出响应。如果您不使用 B+A+Enter 功能,则不需要设置识别器的代理。

- (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.
}

DRKonamiGestureProtocol

仅在您使用 B+A+Enter 功能时需要 DRKonamiGestureProtocol 协议。识别器会在需要 B+A+Enter 序列时通知其代理,并且当序列不再需要时(由于手势失败或成功)也会通知代理。

提示

  • 提示 1:在 DRKonamiGestureRecognizer.m 中禁用了 NSLog() 语句。您可以在文件顶部启用它们,然后控制台将打印出 konami 状态。
  • 提示 2:在实际示例应用程序中练习执行 konami 手势。有些人难以找出如何开始。