iOS开源:TTGPuzzleVerify - 体验更友好的拼图验证控件

ijionscan 7年前
   <h2>TTGPuzzleVerify</h2>    <p><img src="https://simg.open-open.com/show/9790dee097468c5f9ed61d6969ac4ef2.jpg"></p>    <p style="text-align:center"><img src="https://simg.open-open.com/show/dedea7ad9c0b10abe18d0955fd5820a7.gif"></p>    <h2>What</h2>    <p>By completing <strong>image puzzle game</strong> , TTGPuzzleVerify is a <strong>more user-friendly</strong> verification tool on iOS, which is highly customizable and easy to use. It supports square, circle, classic or custom puzzle shape. User can complete the verification by sliding horizontally, vertically or directly dragging the puzzle block.</p>    <h2>Features</h2>    <ul>     <li>More user-friendly</li>     <li>Highly Customizable</li>     <li>Classic, square, circle or custom puzzle shape</li>     <li>Slide horizontally or vertically or drag the puzzle directly</li>    </ul>    <h2>Example</h2>    <p>To run the example project, clone the repo, and run pod install from the Example directory first.</p>    <h2>Requirements</h2>    <p>iOS 7 and later.</p>    <h2>Installation</h2>    <p>TTGPuzzleVerify is available through CocoaPods . To install it, simply add the following line to your Podfile:</p>    <pre>  <code class="language-objectivec">pod "TTGPuzzleVerify"</code></pre>    <h2>Usage</h2>    <p>TTGPuzzleVerifyView</p>    <h3>Basic use</h3>    <pre>  <code class="language-objectivec">// Import  #import <TTGPuzzleVerify/TTGPuzzleVerifyView.h>    - (void)viewDidLoad {      [super viewDidLoad];        // Create TTGPuzzleVerifyView instance      _puzzleVerifyView = [[TTGPuzzleVerifyView alloc] initWithFrame:CGRectMake(20, 20, 320, 200)];      [self.view addSubview:_puzzleVerifyView];        // Set image      _puzzleVerifyView.image = [UIImage imageNamed:@"pic"];        // Set the puzzle blank position      _puzzleVerifyView.puzzleBlankPosition = CGPointMake(200, 40);        // Set init puzzle position      _puzzleVerifyView.puzzlePosition = CGPointMake(10, 40);        // Callback      [_puzzleVerifyView setVerificationChangeBlock:^(TTGPuzzleVerifyView *view, BOOL isVerified) {          if (isVerified) {              // User complete the verification          }      }];  }    // On slide changed  - (IBAction)onSliderChange:(UISlider *)sender {      // Update position      _puzzleVerifyView.puzzleXPercentage = sender.value;  }</code></pre>    <h3>API</h3>    <p>Puzzle pattern types</p>    <pre>  <code class="language-objectivec">/**   * TTGPuzzleVerifyView pattern type   */  typedef NS_ENUM(NSInteger, TTGPuzzleVerifyPattern) {      TTGPuzzleVerifyClassicPattern = 0, // Default      TTGPuzzleVerifySquarePattern,      TTGPuzzleVerifyCirclePattern,      TTGPuzzleVerifyCustomPattern  };    // Puzzle pattern, default is TTGPuzzleVerifyClassicPattern  @property (nonatomic, assign) TTGPuzzleVerifyPattern puzzlePattern;    // Custom path for puzzle shape. Only work when puzzlePattern is TTGPuzzleVerifyCustomPattern  @property (nonatomic, strong) UIBezierPath *customPuzzlePatternPath;</code></pre>    <p>Complete the puzzle with animation</p>    <pre>  <code class="language-objectivec">/**   Complete verification. Call this with set the puzzle to its original position and fill the blank.     @param withAnimation if show animation   */  - (void)completeVerificationWithAnimation:(BOOL)withAnimation;</code></pre>    <p>Callback</p>    <pre>  <code class="language-objectivec">/**   * Verification changed callback delegate   */  @protocol TTGPuzzleVerifyViewDelegate <NSObject>  @optional  - (void)puzzleVerifyView:(TTGPuzzleVerifyView *)puzzleVerifyView didChangedVerification:(BOOL)isVerified;    - (void)puzzleVerifyView:(TTGPuzzleVerifyView *)puzzleVerifyView didChangedPuzzlePosition:(CGPoint)newPosition               xPercentage:(CGFloat)xPercentage yPercentage:(CGFloat)yPercentage;  @end    // Callback block and delegate  @property (nonatomic, weak) id <TTGPuzzleVerifyViewDelegate> delegate; // Callback delegate  @property (nonatomic, copy) void (^verificationChangeBlock)(TTGPuzzleVerifyView *puzzleVerifyView, BOOL isVerified); // verification changed callback block</code></pre>    <p>Puzzle image</p>    <pre>  <code class="language-objectivec">@property (nonatomic, strong) UIImage *image; // Image for verification</code></pre>    <p>Puzzle size and position</p>    <pre>  <code class="language-objectivec">// Puzzle rect size,not for TTGPuzzleVerifyCustomPattern pattern  @property (nonatomic, assign) CGSize puzzleSize;    // Puzzle blank position  @property (nonatomic, assign) CGPoint puzzleBlankPosition;    // Puzzle current position  @property (nonatomic, assign) CGPoint puzzlePosition;    // Puzzle current X and Y position percentage, range: [0, 1]  @property (nonatomic, assign) CGFloat puzzleXPercentage;  @property (nonatomic, assign) CGFloat puzzleYPercentage;</code></pre>    <p>Puzzle verification</p>    <pre>  <code class="language-objectivec">// Verification  @property (nonatomic, assign) CGFloat verificationTolerance; // Verification tolerance, default is 8  @property (nonatomic, assign, readonly) BOOL isVerified; // Verification boolean</code></pre>    <p>Style</p>    <pre>  <code class="language-objectivec">/**   * Style   */    // Puzzle blank alpha, default is 0.5  @property (nonatomic, assign) CGFloat puzzleBlankAlpha;    // Puzzle blank inner shadow  @property (nonatomic, strong) UIColor *puzzleBlankInnerShadowColor; // Default: black  @property (nonatomic, assign) CGFloat puzzleBlankInnerShadowRadius; // Default: 4  @property (nonatomic, assign) CGFloat puzzleBlankInnerShadowOpacity; // Default: 0.5  @property (nonatomic, assign) CGSize puzzleBlankInnerShadowOffset; // Default: (0, 0)    // Puzzle shadow  @property (nonatomic, strong) UIColor *puzzleShadowColor; // Default: black  @property (nonatomic, assign) CGFloat puzzleShadowRadius; // Default: 4  @property (nonatomic, assign) CGFloat puzzleShadowOpacity; // Default: 0.5  @property (nonatomic, assign) CGSize puzzleShadowOffset; // Default: (0, 0)</code></pre>    <h2>Example</h2>    <p>For more information, you can download the zip and run the example.</p>    <p> </p>    <p>来自:https://github.com/zekunyan/TTGPuzzleVerify</p>    <p> </p>