本文实例为大家分享了iOS倒计时获取验证码的具体代码,供大家参考,具体内容如下
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
/**重新发送短信的计时*/
-(void)fireTimer{
__block int timeout=180; //倒计时时间
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
dispatch_source_set_event_handler(_timer, ^{
if(timeout<=0){ //倒计时结束,关闭
dispatch_source_cancel(_timer);
dispatch_async(dispatch_get_main_queue(), ^{
//设置界面的按钮显示 根据自己需求设置
[_changeCodeButton setTitle:@"获取验证码" forState:UIControlStateNormal];
_changeCodeButton.userInteractionEnabled = YES;
});
}else{
int seconds = timeout ;//% 60;
NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
dispatch_async(dispatch_get_main_queue(), ^{
//设置界面的按钮显示 根据自己需求设置
//NSLog(@"____%@",strTime);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
_changeCodeButton.titleLabel.font = [UIFont systemFontOfSize:14];
[_changeCodeButton setTitle:[NSString stringWithFormat:@"(%@s)后重新获取",strTime] forState:UIControlStateNormal];
[UIView commitAnimations];
_changeCodeButton.userInteractionEnabled = NO;
});
timeout--;
}
});
dispatch_resume(_timer);
}
|
上面这段方法是很久以前转自某某博主的,由于找不到地址,不过很有用所以暂且收录在这里,见谅。
还没有整理出来,继续更新中
先为大家分享其他案例:IOS实现验证码倒计时功能(一)、IOS实现验证码倒计时功能(二)
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持快网idc。
相关文章
猜你喜欢
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
- 64M VPS建站:能否支持高流量网站运行? 2025-06-10
- 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10
- 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
- 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-25 97
-
2025-05-29 66
-
2025-05-29 95
-
2025-06-04 99
-
Debian 8或Debian 9(64 位)安装 .NET Core
2025-05-29 109
热门评论

