登录/注册- 滑动拼图验证码(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)
    }
}
相关推荐
Fairy要carry3 分钟前
面试-GRPO强化学习
开发语言·人工智能
Liekkas Kono15 分钟前
RapidOCR Python 贡献指南
开发语言·python·rapidocr
张张努力变强21 分钟前
C++ STL string 类:常用接口 + auto + 范围 for全攻略,字符串操作效率拉满
开发语言·数据结构·c++·算法·stl
2501_9151063223 分钟前
app 上架过程,安装包准备、证书与描述文件管理、安装测试、上传
android·ios·小程序·https·uni-app·iphone·webview
xyq202424 分钟前
Matplotlib 绘图线
开发语言
m0_6948455727 分钟前
tinylisp 是什么?超轻量 Lisp 解释器编译与运行教程
服务器·开发语言·云计算·github·lisp
春日见32 分钟前
如何创建一个PR
运维·开发语言·windows·git·docker·容器
2501_9151063233 分钟前
使用 Sniffmaster TCP 抓包和 Wireshark 网络分析
网络协议·tcp/ip·ios·小程序·uni-app·wireshark·iphone
C++ 老炮儿的技术栈36 分钟前
VS2015 + Qt 实现图形化Hello World(详细步骤)
c语言·开发语言·c++·windows·qt
派葛穆42 分钟前
Python-批量安装依赖
开发语言·python