登录/注册- 滑动拼图验证码(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)
    }
}
相关推荐
阿正的梦工坊4 小时前
JavaScript 微任务与宏任务完全指南
开发语言·javascript·ecmascript
知行合一。。。5 小时前
Python--05--面向对象(属性,方法)
android·开发语言·python
青梅橘子皮5 小时前
C语言---指针的应用以及一些面试题
c语言·开发语言·算法
浅时光_c6 小时前
3 shell脚本编程
linux·开发语言·bash
Evand J6 小时前
【三维轨迹目标定位,CKF+RTS,MATLAB程序】基于CKF与RTS平滑的三维非线性目标跟踪(距离+方位角+俯仰角)
开发语言·matlab·目标跟踪
今天又在写代码7 小时前
java-v2
java·开发语言
competes7 小时前
慈善基金投资底层逻辑应用 顶层代码低代码配置平台开发结构方式数据存储模块
java·开发语言·数据库·windows·sql
Ulyanov8 小时前
用Pyglet打造AI数字猎人:从零开始的Python游戏开发与强化学习实践
开发语言·人工智能·python
独自归家的兔8 小时前
OCPP 1.6 协议详解:StatusNotification 状态通知指令
开发语言·数据库·spring boot·物联网
希望永不加班8 小时前
Spring AOP 代理模式:CGLIB 与 JDK 动态代理区别
java·开发语言·后端·spring·代理模式