TTGPuzzleVerify is a native iOS puzzle verification component. It supports image or gradient puzzle backgrounds, built-in and custom puzzle paths, configurable verification behavior, behavior metrics, and UIKit / SwiftUI / Objective-C integration from one shared core.
- Native UIKit core with SwiftUI and Objective-C interoperability.
- Image, remote image, or generated gradient puzzle backgrounds.
- Classic, square, circle, and custom
UIBezierPathpuzzle shapes. - Horizontal, vertical, or free two-axis dragging.
- Manual verification or automatic verification with configurable tolerance.
- Success snap, failure feedback, reset, retry, and lock states.
- Rich result payload with offsets, elapsed time, drag distance, interaction count, and optional track samples.
- CocoaPods and Swift Package Manager support for iOS 16+.
The component is organized as one shared TTGPuzzleVerifyView core. Integration surfaces configure the same rendering, pattern, interaction, verification, and metrics modules, so SwiftUI, UIKit, and Objective-C demos stay behaviorally consistent.
platform :ios, '16.0'
use_frameworks!
pod "TTGPuzzleVerify"Add this repository as an iOS 16+ package dependency. The package product is TTGPuzzleVerify.
The editable quick start source lives in Resources/Marketing/quick_start.html, built from real screenshots under Resources/Marketing/assets.
import TTGPuzzleVerify
struct PuzzleVerifyRepresentable: UIViewRepresentable {
@Binding var isVerified: Bool
func makeUIView(context: Context) -> TTGPuzzleVerifyView {
let view = TTGPuzzleVerifyView()
view.image = UIImage(named: "background")
let configuration = TTGPuzzleVerifyConfiguration()
configuration.puzzlePattern = .classicPattern
configuration.puzzleSize = CGSize(width: 86, height: 86)
configuration.allowedAxes = .both
configuration.autoSnapWhenWithinTolerance = true
view.applyConfiguration(configuration)
view.puzzleBlankPosition = CGPoint(x: 220, y: 96)
view.verificationChangeBlock = { _, verified in
isVerified = verified
}
return view
}
}import TTGPuzzleVerify
let puzzleView = TTGPuzzleVerifyView()
puzzleView.image = UIImage(named: "background")
let configuration = TTGPuzzleVerifyConfiguration()
configuration.puzzlePattern = .circlePattern
configuration.puzzleSize = CGSize(width: 92, height: 92)
configuration.allowedAxes = .horizontal
configuration.verificationTolerance = 7
puzzleView.applyConfiguration(configuration)
puzzleView.puzzleBlankPosition = CGPoint(x: 210, y: 20)
puzzleView.resetVerification()#import <TTGPuzzleVerify/TTGPuzzleVerify-Swift.h>
TTGPuzzleVerifyView *puzzleView = [[TTGPuzzleVerifyView alloc] init];
TTGPuzzleVerifyConfiguration *configuration = [[TTGPuzzleVerifyConfiguration alloc] init];
configuration.puzzlePattern = TTGPuzzleVerifyPatternClassicPattern;
configuration.allowedAxes = TTGPuzzleVerifyAllowedAxesBoth;
configuration.autoSnapWhenWithinTolerance = YES;
[puzzleView applyConfiguration:configuration];
puzzleView.puzzleBlankPosition = CGPointMake(220, 96);
[puzzleView resetVerification];let configuration = TTGPuzzleVerifyConfiguration()
configuration.puzzlePattern = .classicPattern
configuration.allowedAxes = .horizontal
configuration.autoSnapWhenWithinTolerance = true
puzzleView.image = UIImage(named: "pic3")
puzzleView.applyConfiguration(configuration)
puzzleView.puzzleBlankPosition = CGPoint(x: 200, y: 20)
puzzleView.resetVerification()The repository includes two runnable example apps:
- Objective-C UIKit example: run
pod installfromExamples/ObjCExample, then openExamples/ObjCExample/TTGPuzzleVerify.xcworkspace. - Swift example with UIKit and SwiftUI demos: run
pod installfromExamples/SwiftExample, then openExamples/SwiftExample/TTGPuzzleVerifySwiftExample.xcworkspace.
public enum TTGPuzzleVerifyPattern: Int {
case classicPattern
case squarePattern
case circlePattern
case customPattern
}public enum TTGPuzzleVerifyAllowedAxes: Int {
case horizontal
case vertical
case both
}public enum TTGPuzzleVerifyState: Int {
case idle
case dragging
case verified
case failed
case locked
}TTGPuzzleVerifyResult includes:
isVerifiedpuzzlePositionblankPositionxOffset/yOffsetelapsedTimedragDistanceinteractionCount
Use TTGPuzzleVerifyConfiguration to apply behavior consistently:
puzzlePatternpuzzleSizeverificationToleranceallowedAxesautoSnapWhenWithinTolerancerecordsTrackmaxRetryCountstyle
- iOS 16.0+
- Xcode 15+
Objective-C tests cover default configuration, clamping, percentage mapping, verification tolerance, callbacks, configuration/style application, failure locking, result creation, and track collection.
cd Examples/ObjCExample
pod install
xcodebuild -workspace TTGPuzzleVerify.xcworkspace -scheme TTGPuzzleVerify-Example -destination 'platform=iOS Simulator,name=iPhone 17' testThe editable HTML sources live in Resources/Marketing:
promo_poster.html->promo_poster.jpgarchitecture_diagram.html->architecture_diagram.jpgquick_start.html->quick_start.jpg
zekunyan, zekunyan@163.com
TTGPuzzleVerify is available under the MIT license. See the LICENSE file for more info.


