欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 高考 > 登录/注册- 滑动拼图验证码(IOS/Swift)

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

2024/10/23 23:31:57 来源:https://blog.csdn.net/qq_37523448/article/details/139624906  浏览:    关键词:登录/注册- 滑动拼图验证码(IOS/Swift)

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

1.导入项目model文件OC代码(下载完整Demo)
在这里插入图片描述

2.放入你需要显示的图片
在这里插入图片描述

一:OC调用

#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调用

import UIKitclass 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 = selfcodeView.passDistance = 2// 设置自定义视图的布局约束,可以根据需要进行调整codeView.center = self.view.centercodeView.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 inif subview is CodeView {subview.removeFromSuperview()}}}func codeViewAuthenticationResult(_ result: Bool) {print("code%@ == ",result)}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com