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

打印 上一主题 下一主题

主题 950|帖子 950|积分 2860

本章介绍如何利用ios开辟出滑动拼图验证码,分别OC代码和swift代码调用
1.导入项目model文件OC代码(下载完整Demo)

2.放入你需要表现的图片

一:OC调用

  1. #import "ViewController.h"
  2. #import "CodeView.h"
  3. @interface ViewController () <CodeViewDelegate>
  4. @property (nonatomic, strong) CodeView * codeView;
  5. @end
  6. @implementation ViewController
  7. - (void)viewDidLoad {
  8.     [super viewDidLoad];
  9.     // Do any additional setup after loading the view, typically from a nib.
  10.     _codeView = [[CodeView alloc]initWithFrame:self.view.frame];
  11.     [self.view addSubview:_codeView];
  12.     _codeView.delegate = self;
  13.     _codeView.passDistance = 2;
  14.     self.view.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.8];
  15. }
  16. - (void)codeViewAuthenticationResult:(BOOL)result
  17. {
  18.     NSLog(@"验证%@通过", result ? @"" : @"不");
  19. }
  20. - (void)viewWillAppear:(BOOL)animated
  21. {
  22.     [super viewWillAppear:animated];
  23.     [_codeView setCodeImage:[UIImage imageNamed:@"testB.jpg"]];
  24. }
  25. - (void)didReceiveMemoryWarning {
  26.     [super didReceiveMemoryWarning];
  27.     // Dispose of any resources that can be recreated.
  28. }
  29. @end
复制代码
二:swift调用

  1. import UIKit
  2. class MeViewController: BaseViewController,CodeViewDelegate{
  3.     private var codeView = CodeView()
  4.     private let meView = MeView()
  5.     override func initData() {
  6.         // 显示自定义视图弹窗
  7.         showCustomPopup()
  8.     }
  9. // 显示自定义视图弹窗
  10.     func showCustomPopup() {
  11.         // 实例化自定义视图
  12.         codeView = CodeView(frame: CGRect(x: 0, y: 0, width: ALERTVIEW_WIDTH - 150, height: ALERTVIEW_HEIGHT))
  13.         // 设置自定义视图的样式和内容
  14.         // 添加到当前视图控制器的视图上
  15.         //let customView = CodeView(frame: self.view.frame)
  16. //            self.view.addSubview(codeView)
  17.         codeView.delegate = self
  18.         codeView.passDistance = 2
  19.         // 设置自定义视图的布局约束,可以根据需要进行调整
  20.         codeView.center = self.view.center
  21.         codeView.setCodeImage(UIImage(named: "testA.jpg"))
  22.         meView.addSubview(codeView)
  23.         // 添加点击背景关闭弹窗的逻辑(可选)
  24.         let tapGesture = UITapGestureRecognizer(target: self, action: #selector(dismissCustomPopup))
  25.         codeView.addGestureRecognizer(tapGesture)
  26.     }
  27.    
  28.     // 点击背景关闭弹窗的逻辑(可选)
  29.     @objc func dismissCustomPopup() {
  30.         // 移除自定义视图
  31.         self.view.subviews.forEach { subview in
  32.             if subview is CodeView {
  33.                 subview.removeFromSuperview()
  34.             }
  35.         }
  36.     }
  37.    
  38.     func codeViewAuthenticationResult(_ result: Bool) {
  39.         print("code%@ == ",result)
  40.     }
  41. }
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

宁睿

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表