DBGuestureLock 0.0.2

DBGuestureLock 0.0.2

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布上次发布2016年2月

i36lib 维护。



  • 作者:
  • i36.Me

DBGuestureLock 中文

DBGuestureLock 是一个非常易于使用的 iOS 插件类。我欢迎您为 DBGuestureLock 添加任何额外的实用功能,使其变得更好。如果您想为此项目做出贡献,只需提交一个拉取请求。如果您喜欢这个项目,请给它加星!

第1节 要求

DBGuestureLock 在 iOS SDK9.2Xcode7.2.1(7C1002) 下构建,并通过了我们使用 Xcode7 和 iOS SDK9.0 在 travis-ci 上的测试。您应该在 ARC 下使用 DBGuestureLock。

  • UIKit.framework

第2节 将 DBGuestureLock 添加到您的项目中

源文件

只需将 DBGuestureButton.hDBGuestureButton.mDBGuestureLock.hDBGuestureLock.m 源文件直接添加到您的项目中。

  1. 下载最新的代码版本 https://github.com/i36lib/DBGuestureLock/archive/master.zip 或将存储库作为 git 子模块添加到您的 git 跟踪项目中。
  2. 在 Xcode 中打开您的项目,然后将 4 个源文件拖放到您的项目中(使用“产品导航器视图”)。确保在代码归档相对于您的项目外部提取时选择“复制项”。
  3. 在您想要添加手势锁的 ViewController 中包含 DBGuestureLock,使用 `#import "DBGuestureLock.h"`。

第3节 使用方法

使用 DBGuestureLock 有两种方式:配合委托(delegate)和使用闭包(block)。

使用闭包

最简单的方式,只需导入 DBGuestureLock.h 并输入两个语句

#import "DBGuestureLock.h"

@interface ViewController ()

在 `viewDidLoad` 中创建一个 `GuestureLock` 对象并将其添加为当前视图的子视图

- (void)viewDidLoad {
    [super viewDidLoad];

    [DBGuestureLock clearGuestureLockPassword]; //just for test

    DBGuestureLock *lock = [DBGuestureLock lockOnView:self.view onPasswordSet:^(DBGuestureLock *lock, NSString *password) {
        if (lock.firstTimeSetupPassword == nil) {
            lock.firstTimeSetupPassword = password;
            NSLog(@"varify your password");
            self.label.text = @"Enter your password again:";
        }
    } onGetCorrectPswd:^(DBGuestureLock *lock, NSString *password) {
        if (lock.firstTimeSetupPassword && ![lock.firstTimeSetupPassword isEqualToString:DBFirstTimeSetupPassword]) {
            lock.firstTimeSetupPassword = DBFirstTimeSetupPassword;
            NSLog(@"password has been setup!");
            self.label.text = @"password has been setup!";
        } else {
            NSLog(@"login success");
            self.label.text = @"login success!";
        }
    } onGetIncorrectPswd:^(DBGuestureLock *lock, NSString *password) {
        if (![lock.firstTimeSetupPassword isEqualToString:DBFirstTimeSetupPassword]) {
            NSLog(@"Error: password not equal to first setup!");
            self.label.text = @"Not equal to first setup!";
        } else {
            NSLog(@"login failed");
            self.label.text = @"login failed!";
        }
    }];
    [self.view addSubview:lock];
    [self.view setBackgroundColor:[UIColor colorWithRed:0.133 green:0.596 blue:0.933 alpha:1.00]];
}

如果您需要,调用以下方法设置三个按钮的锁定主题

-(void)setupLockThemeWithLineColor:(UIColor*)lineColor lineWidth:(CGFloat)lineWidth  strokeColor:(UIColor*)strokeColor strokeWidth:(CGFloat)strokeWidth circleRadius:(CGFloat)circleRadius fillColor:(UIColor*)fillColor showCenterPoint:(BOOL)showCenterPoint centerPointColor:(UIColor*)centerPointColor centerPointRadius:(CGFloat)centerPointRadius fillCenterPoint:(BOOL)fillCenterPoint onState:(DBButtonState)buttonState;

使用委托

在您的 `ViewController` 中导入 DBGuestureLock.h 并使您的 `ViewController` 符合 `DBGuestureLockDelegate` 委托

#import "DBGuestureLock.h"

@interface ViewController ()<DBGuestureLockDelegate>

在viewDidLoad方法中创建一个GuestureLock对象并将其添加到你的视图中

- (void)viewDidLoad {
    [super viewDidLoad];

    [DBGuestureLock clearGuestureLockPassword]; //just for test

    DBGuestureLock *lock = [DBGuestureLock lockOnView:self.view delegate:self];
    [self.view addSubview:lock];
    [self.view setBackgroundColor:[UIColor colorWithRed:0.133 green:0.596 blue:0.933 alpha:1.00]];
}

实现3个必需的委托方法

-(void)guestureLock:(DBGuestureLock *)lock didSetPassword:(NSString *)password {
    // test
    if (lock.firstTimeSetupPassword == nil) {
        lock.firstTimeSetupPassword = password;
        NSLog(@"varify your password");
        self.label.text = @"Enter your password again:";
    }
}

-(void)guestureLock:(DBGuestureLock *)lock didGetCorrectPswd:(NSString *)password {
    // test
    if (lock.firstTimeSetupPassword && ![lock.firstTimeSetupPassword isEqualToString:DBFirstTimeSetupPassword]) {
        lock.firstTimeSetupPassword = DBFirstTimeSetupPassword;
        NSLog(@"password has been setup!");
        self.label.text = @"password has been setup!";
    } else {
        NSLog(@"login success");
        self.label.text = @"login success!";
    }
}

-(void)guestureLock:(DBGuestureLock *)lock didGetIncorrectPswd:(NSString *)password {
    // test
    if (![lock.firstTimeSetupPassword isEqualToString:DBFirstTimeSetupPassword]) {
        NSLog(@"Error: password not equal to first setup!");
        self.label.text = @"Not equal to first setup!";
    } else {
        NSLog(@"login failed");
        self.label.text = @"login failed!";
    }
}

一些其他可选的委托方法允许你更改锁的样式

-(BOOL)showButtonCircleCenterPointOnState:(DBButtonState)buttonState;
-(BOOL)fillButtonCircleCenterPointOnState:(DBButtonState)buttonState;//NO for stroke, YES for fill
-(CGFloat)widthOfButtonCircleStrokeOnState:(DBButtonState)buttonState;
-(CGFloat)radiusOfButtonCircleCenterPointOnState:(DBButtonState)buttonState;
-(CGFloat)lineWidthOfGuestureOnState:(DBButtonState)buttonState;
-(UIColor *)colorOfButtonCircleStrokeOnState:(DBButtonState)buttonState;
-(UIColor *)colorForFillingButtonCircleOnState:(DBButtonState)buttonState;
-(UIColor *)colorOfButtonCircleCenterPointOnState:(DBButtonState)buttonState;
-(UIColor *)lineColorOfGuestureOnState:(DBButtonState)buttonState;

其他方法和属性

DBButtonState包含

DBButtonStateNormal     //Normal state button
DBButtonStateSelected   //when button is selected
DBButtonStateIncorrect  //when password is incorrect

其他类方法/属性允许你操作密码(密码保存在UserDefaults中)

+(BOOL)passwordSetupStatus;
+(void)clearGuestureLockPassword;
+(NSString *)getGuestureLockPassword;
@property (nonatomic, readonly, assign)BOOL isPasswordSetup;

第4节 许可证

此代码根据MIT许可证的条款和条件分发。

第5节 更新日志

  1. 2016/02/28: 第一次提交。CocoaPods兼容。完成用户指南。与委托一起工作。
  2. 2016/02/29: 更新并使其支持使用block。可以选择两种使用方式(Block/Delegate)。