• Stars
    star
    353
  • Rank 120,322 (Top 3 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created almost 8 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

By completing image puzzle game, TTGPuzzleVerify is a more user-friendly verification tool on iOS, which is highly customizable and easy to use. 体验更友好的拼图验证控件

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:

pod "TTGPuzzleVerify"

Usage

TTGPuzzleVerifyView

Basic use

// 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;
}

API

Puzzle pattern types

/**
 * 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;

Complete the puzzle with animation

/**
 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;

Callback

/**
 * 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

Puzzle image

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

Puzzle size and position

// 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;

Puzzle verification

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

Style

/**
 * 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)

Example

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

Author

zekunyan, [email protected]

License

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

More Repositories

1

TTGTagCollectionView

Useful for showing text or custom view tags in a vertical or horizontal scrollable view and support Autolayout at the same time. It is highly customizable that most features of the text tag can be configured. 标签流显示控件,同时支持文字或自定义View
Objective-C
1,822
star
2

AutolayoutExampleWithMasonry

Different Autolayout examples with Masonry. 用Masonry写的Autolayout案例,持续更新中。详细解答请看tutuge.me
Objective-C
707
star
3

TTGSnackbar

TTGSnackbar shows simple message and action button on the bottom or top of the screen with multi kinds of animation, which is written in Swift3 and inspired by Snackbar in Android. It also support showing custom view, icon image or multi action button.
Swift
634
star
4

TTGEmojiRate

An emoji-liked rating view for iOS, implemented in Swift3.
Swift
289
star
5

TTGBingWallPaper

Mac menubar app. Automate download daily picture from Microsoft Bing website and set it as your wallpaper. Written in Swift3.
Swift
183
star
6

UITextViewDIYEmojiExample

Example of insert custom emoji image in to UITextView. And get the represent string back after editing.
Objective-C
149
star
7

HttpProxyExample

HttpProxyExample-Example of using NSProxy
Objective-C
47
star
8

iOS-Tasks

ITEC学习iOS同学的Github聚集地=。=
Objective-C
43
star
9

AutoReleasePoolTestExample

An example to figure out the benefit to use @autoreleasepool in ARC iOS program.
Objective-C
30
star
10

TTGDeallocTaskHelper

NSObject Category to add callback tasks when object dealloc.
Shell
29
star
11

LinkTextView

An Android TextView to add highly customizable and colorful link.
Java
29
star
12

ThriftDemo_PHP_CPP

Demo for Thrift RPC framework. PHP client call CPP server.
PHP
29
star
13

QuartzCodeExample-StarAimation

QuartzCode star-style animation demo.
Objective-C
27
star
14

TTGNotificationGuard

Auto remove the observer from NSNotificationCenter after the oberser dealloc
Shell
13
star
15

TTGRemakeMethodSignatureForSelector

Remake methodSignatureForSelector. Just for research. :)
Objective-C
10
star
16

OutParameterPointerCrashOnXcode8

Example code for out parameter pointer EXC_BAD_ACCESS crash on Xcode 8
C++
4
star
17

TTGKVOGuard

Auto remove KVO observer from object after it dealloc.
Objective-C
2
star
18

zekunyan.github.io

tutuge blog
HTML
1
star