[翻译] 带有震动效果的 ShakingAlertView

ShakingAlertView  震动效果的AlertView

[翻译] 带有震动效果的 ShakingAlertView

https://github.com/lukestringer90/ShakingAlertView

ShakingAlertView is a UIAlertView subclass with a password entry textfield. Incorrect password entry causes a "shake" animation similar to the OS X account login screen.

这是一个UIAlertView的子类并带有一个密码输入的textfield。输入错误的密码会触发震动效果,与 OS X 登陆界面相似。

[翻译] 带有震动效果的 ShakingAlertView

Installation

Cocoapods

用COcoapods安装:

Add to your Podfile:

pod 'ShakingAlertView'

Adding source code manually

Clone the git repo and drag the "src" folder into your project. This contains the UI components and cryptographic helpers necessary for hashing passwords.

将“src”文件夹拖入到工程当中。这个文件夹包含了UI显示组件以及给密码加密用的文件。

Usage

Plaintext password

Use ShakingAlertView just like UIAlertView. For a checking a plain text password:

你可以像使用UIAlertView那样子来使用ShakingAlertView。检查文本合法性参考如下:

ShakingAlertView *shakingAlert = nil;

shakingAlert = [[ShakingAlertView alloc] initWithAlertTitle:@"Enter Password"

                                           checkForPassword:@"pass"];



[shakingAlert setOnCorrectPassword:^{

    // Code to execute on correct password entry

}];



[shakingAlert setOnDismissalWithoutPassword:^{

    // Code to execute on alert dismissal without password entry

}];



[shakingAlert show];

Rather than using a delegate, pass the instance a completion block to be executed for correct password entry and alert dismissal. ShakingAlertView uses ARC so no need to release your instances.

使用代理,或者传递一个block的实例变量来判断文本输入正确或者错误的执行入口。ShakingAlertView使用ARC所以不需要你来释放你的实例变量。

Hashed passwords

ShakingAlertView uses the Common Crypto C API to hash the entered text to SHA1 or MD5. Therefore if you only know the hashed counterpart of a password string you can specify this along with the hashing algorithm type in the constructor.

ShakingAlertView使用了通用C接口的SHA1或者MD5来加密文本。你可以指定某种加密方式来加密。

ShakingAlertView *shakingAlert = nil;

shakingAlert = [[ShakingAlertView alloc] initWithAlertTitle:@"Enter Password"

                                           checkForPassword:@"W6ph5Mm5Pz8GgiULbPgzG37mj9g=" //sha1 hash of 'password'

                                      usingHashingTechnique:HashTechniqueSHA1];



The hashing algorithm to use is defined by an enum and passed into the constructor.

加密算法用枚举值来标示。

typedef enum {

    HashTechniqueNone,

    HashTechniqueSHA1,

    HashTechniqueMD5

} HashTechnique;

HashTechniqueNone is used if no technique is specified, like in the initWithAlertTitle:checkForPassword andinitWithAlertTitle:checkForPassword:onCorrectPassword:onDismissalWithoutPassword constructors. Here the entered string is compared with the specified plaintext password using a simple isEqualToString: evaluation.

如果是显示标题,那就使用HashTechniqueNone。

Running the tests

The ShakingAlertView class is tested using the BDD tool Kiwi. To run the tests install Kiwi via Cocoapods, and the open the workspace:

cd Example\ Project/

pod install

open ExampleProject.xcworkspace/

Make sure the "ShakingAlertView" scheme is selected then run the tests with ⌘+U

Acknowledgements

NSData+Base64.h/m and b64.h/m from aqtoolkit by Jim Dovey

Kiwi testing tool.

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(alert)