登录/注册- 滑动拼图验证码(IOS/Swift)

本章介绍如何使用ios开发出滑动拼图验证码,分别OC代码和swift代码调用

1.导入项目model文件OC代码(下载完整Demo

2.放入你需要显示的图片

一:OC调用

bash 复制代码
#import "ViewController.h"
#import "CodeView.h"

@interface ViewController () <CodeViewDelegate>
@property (nonatomic, strong) CodeView * codeView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    _codeView = [[CodeView alloc]initWithFrame:self.view.frame];
    [self.view addSubview:_codeView];
    _codeView.delegate = self;
    _codeView.passDistance = 2;
    self.view.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.8];
}

- (void)codeViewAuthenticationResult:(BOOL)result
{
    NSLog(@"验证%@通过", result ? @"" : @"不");
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [_codeView setCodeImage:[UIImage imageNamed:@"testB.jpg"]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

二:swift调用

bash 复制代码
import UIKit

class MeViewController: BaseViewController,CodeViewDelegate{
    private var codeView = CodeView()
    private let meView = MeView()

    override func initData() {
        // 显示自定义视图弹窗
        showCustomPopup()
    }

// 显示自定义视图弹窗
    func showCustomPopup() {
        // 实例化自定义视图
        codeView = CodeView(frame: CGRect(x: 0, y: 0, width: ALERTVIEW_WIDTH - 150, height: ALERTVIEW_HEIGHT))
        // 设置自定义视图的样式和内容
        // 添加到当前视图控制器的视图上
        //let customView = CodeView(frame: self.view.frame)
//            self.view.addSubview(codeView)
        codeView.delegate = self
        codeView.passDistance = 2
        // 设置自定义视图的布局约束,可以根据需要进行调整
        codeView.center = self.view.center
        codeView.setCodeImage(UIImage(named: "testA.jpg"))
        meView.addSubview(codeView)
        // 添加点击背景关闭弹窗的逻辑(可选)
        let tapGesture = UITapGestureRecognizer(target: self, action: #selector(dismissCustomPopup))
        codeView.addGestureRecognizer(tapGesture)
    }
    
    // 点击背景关闭弹窗的逻辑(可选)
    @objc func dismissCustomPopup() {
        // 移除自定义视图
        self.view.subviews.forEach { subview in
            if subview is CodeView {
                subview.removeFromSuperview()
            }
        }
    }
    
    func codeViewAuthenticationResult(_ result: Bool) {
        print("code%@ == ",result)
    }
}
相关推荐
山西茄子5 分钟前
GstAggregator的aggregate
开发语言·前端·javascript·gstreamer
南境十里·墨染春水7 分钟前
C++传记 详解单例模式(面向对象)
开发语言·c++·单例模式
cui_ruicheng13 分钟前
C++智能指针:从 RAII 到 shared_ptr 源码实现
开发语言·c++
爱丽_15 分钟前
AQS 的 CLH 同步队列:入队/出队、park/unpark 与“公平性”从哪来
java·开发语言·jvm
共享家952715 分钟前
实现简化的高性能并发内存池
开发语言·数据结构·c++·后端
千里马学框架16 分钟前
aospc/c++的native 模块VScode和Clion
android·开发语言·c++·vscode·安卓framework开发·clion·车载开发
liuqun031923 分钟前
go进阶之gc
开发语言·后端·golang
武藤一雄31 分钟前
深入理解 C# 中的 sizeof 与非托管类型约束
开发语言·windows·c#·.net·.netcore
好家伙VCC31 分钟前
**发散创新:用 Rust实现数据编织(DataWrangling)的高效流式处理架构**在现
java·开发语言·python·架构·rust
2401_8769075235 分钟前
《Python深度学习》
开发语言·python·深度学习