项目作者: zekunyan

项目描述 :
By completing image puzzle game, TTGPuzzleVerify is a more user-friendly verification tool on iOS, which is highly customizable and easy to use. 体验更友好的拼图验证控件
高级语言: Objective-C
项目地址: git://github.com/zekunyan/TTGPuzzleVerify.git


TTGPuzzleVerify

CI Status
Version
License
Platform

Screenshot

Gif

What

By completing image puzzle game, TTGPuzzleVerify is a more user-friendly 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.

Features

  • More user-friendly
  • Highly Customizable
  • Classic, square, circle or custom puzzle shape
  • Slide horizontally or vertically or drag the puzzle directly

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

iOS 7 and later.

Installation

TTGPuzzleVerify is available through CocoaPods. To install
it, simply add the following line to your Podfile:

  1. pod "TTGPuzzleVerify"

Usage

TTGPuzzleVerifyView

Basic use

  1. // Import
  2. #import <TTGPuzzleVerify/TTGPuzzleVerifyView.h>
  3. - (void)viewDidLoad {
  4. [super viewDidLoad];
  5. // Create TTGPuzzleVerifyView instance
  6. _puzzleVerifyView = [[TTGPuzzleVerifyView alloc] initWithFrame:CGRectMake(20, 20, 320, 200)];
  7. [self.view addSubview:_puzzleVerifyView];
  8. // Set image
  9. _puzzleVerifyView.image = [UIImage imageNamed:@"pic"];
  10. // Set the puzzle blank position
  11. _puzzleVerifyView.puzzleBlankPosition = CGPointMake(200, 40);
  12. // Set init puzzle position
  13. _puzzleVerifyView.puzzlePosition = CGPointMake(10, 40);
  14. // Callback
  15. [_puzzleVerifyView setVerificationChangeBlock:^(TTGPuzzleVerifyView *view, BOOL isVerified) {
  16. if (isVerified) {
  17. // User complete the verification
  18. }
  19. }];
  20. }
  21. // On slide changed
  22. - (IBAction)onSliderChange:(UISlider *)sender {
  23. // Update position
  24. _puzzleVerifyView.puzzleXPercentage = sender.value;
  25. }

API

Puzzle pattern types

  1. /**
  2. * TTGPuzzleVerifyView pattern type
  3. */
  4. typedef NS_ENUM(NSInteger, TTGPuzzleVerifyPattern) {
  5. TTGPuzzleVerifyClassicPattern = 0, // Default
  6. TTGPuzzleVerifySquarePattern,
  7. TTGPuzzleVerifyCirclePattern,
  8. TTGPuzzleVerifyCustomPattern
  9. };
  10. // Puzzle pattern, default is TTGPuzzleVerifyClassicPattern
  11. @property (nonatomic, assign) TTGPuzzleVerifyPattern puzzlePattern;
  12. // Custom path for puzzle shape. Only work when puzzlePattern is TTGPuzzleVerifyCustomPattern
  13. @property (nonatomic, strong) UIBezierPath *customPuzzlePatternPath;

Complete the puzzle with animation

  1. /**
  2. Complete verification. Call this with set the puzzle to its original position and fill the blank.
  3. @param withAnimation if show animation
  4. */
  5. - (void)completeVerificationWithAnimation:(BOOL)withAnimation;

Callback

  1. /**
  2. * Verification changed callback delegate
  3. */
  4. @protocol TTGPuzzleVerifyViewDelegate <NSObject>
  5. @optional
  6. - (void)puzzleVerifyView:(TTGPuzzleVerifyView *)puzzleVerifyView didChangedVerification:(BOOL)isVerified;
  7. - (void)puzzleVerifyView:(TTGPuzzleVerifyView *)puzzleVerifyView didChangedPuzzlePosition:(CGPoint)newPosition
  8. xPercentage:(CGFloat)xPercentage yPercentage:(CGFloat)yPercentage;
  9. @end
  10. // Callback block and delegate
  11. @property (nonatomic, weak) id <TTGPuzzleVerifyViewDelegate> delegate; // Callback delegate
  12. @property (nonatomic, copy) void (^verificationChangeBlock)(TTGPuzzleVerifyView *puzzleVerifyView, BOOL isVerified); // verification changed callback block

Puzzle image

  1. @property (nonatomic, strong) UIImage *image; // Image for verification

Puzzle size and position

  1. // Puzzle rect size,not for TTGPuzzleVerifyCustomPattern pattern
  2. @property (nonatomic, assign) CGSize puzzleSize;
  3. // Puzzle blank position
  4. @property (nonatomic, assign) CGPoint puzzleBlankPosition;
  5. // Puzzle current position
  6. @property (nonatomic, assign) CGPoint puzzlePosition;
  7. // Puzzle current X and Y position percentage, range: [0, 1]
  8. @property (nonatomic, assign) CGFloat puzzleXPercentage;
  9. @property (nonatomic, assign) CGFloat puzzleYPercentage;

Puzzle verification

  1. // Verification
  2. @property (nonatomic, assign) CGFloat verificationTolerance; // Verification tolerance, default is 8
  3. @property (nonatomic, assign, readonly) BOOL isVerified; // Verification boolean

Style

  1. /**
  2. * Style
  3. */
  4. // Puzzle blank alpha, default is 0.5
  5. @property (nonatomic, assign) CGFloat puzzleBlankAlpha;
  6. // Puzzle blank inner shadow
  7. @property (nonatomic, strong) UIColor *puzzleBlankInnerShadowColor; // Default: black
  8. @property (nonatomic, assign) CGFloat puzzleBlankInnerShadowRadius; // Default: 4
  9. @property (nonatomic, assign) CGFloat puzzleBlankInnerShadowOpacity; // Default: 0.5
  10. @property (nonatomic, assign) CGSize puzzleBlankInnerShadowOffset; // Default: (0, 0)
  11. // Puzzle shadow
  12. @property (nonatomic, strong) UIColor *puzzleShadowColor; // Default: black
  13. @property (nonatomic, assign) CGFloat puzzleShadowRadius; // Default: 4
  14. @property (nonatomic, assign) CGFloat puzzleShadowOpacity; // Default: 0.5
  15. @property (nonatomic, assign) CGSize puzzleShadowOffset; // Default: (0, 0)

Example

For more information, you can download the zip and run the example.

Author

zekunyan, zekunyan@163.com

License

TTGPuzzleVerify is available under the MIT license. See the LICENSE file for more info.