美文网首页
60s倒计时(Q群里盆友分享的)

60s倒计时(Q群里盆友分享的)

作者: HuLL乐乐 | 来源:发表于2016-08-27 09:47 被阅读75次

.h

@property (nonatomic, strong)UIButton *verificationCodeButton;

.m

在某个方法里实现

_verificationCodeButton = [UIButton buttonWithType:UIButtonTypeCustom];

_verificationCodeButton.frame = CGRectMake(10, 200, 300, 40);

_verificationCodeButton.backgroundColor = [UIColor grayColor];

[self.view addSubview:_verificationCodeButton];

__block int timeout=59; //倒计时时间

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(), ^{

//设置界面的按钮显示 根据自己需求设置

[_verificationCodeButton setTitle:@"发送验证码" forState:UIControlStateNormal];

_verificationCodeButton.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];

[_verificationCodeButton setTitle:[NSString stringWithFormat:@"%@秒后重新发送",strTime] forState:UIControlStateNormal];

[UIView commitAnimations];

_verificationCodeButton.userInteractionEnabled = NO;

});

timeout--;

}

});

dispatch_resume(_timer);

相关文章

  • 60s倒计时(Q群里盆友分享的)

    .h @property (nonatomic, strong)UIButton *verificationCod...

  • iOS开发-倒计时

    倒计时 倒计时60s 倒计时HH-MM-SS 1.倒计时60s 很多时候在点击按钮发送短信的时候需要倒计时读秒 2...

  • 贡献

    今天管老师在群里发了一个为班里每个小盆友发的奖状,一下子在群里炸开了锅,分分为我们的班主任和小盆友们点赞。...

  • 第一个Q 版人物

    手痒,忍不住画个Q 版小盆友,开启《Q 版漫画技法》第一步,开心~

  • 关于大盆友小盆友学英语的Q&A

    我在一个小型封闭式读书群里领读了一本关于育儿的书,当读到关于英语学习的部分时,不谦虚地多说了一些自己的看法和经验。...

  • 2018-01-10

    2018年1月10日 (8/365) 老师在群里通知,今天孩小盆友参加学习小组,晚一小时去接! 接到小盆友之后,开...

  • 非著名房投人  网友问答精选!!

    格言:我最关心的不是房价涨跌,而是面对涨跌,怎么做对我最有利!! 分享的初衷缘于群里某位小盆友给我发了个66的红包...

  • 20180620星期三|抓住机会高度曝光

    记录:今天60s,只练习了一遍,我跑到多个群里大笑60s,感觉嗓子开了,读起来顺多了。一直在Sara早起言值群里练...

  • 位置

    大宝贝幼儿园家长群里老师发了近期采摘活动的后续分享照片,如下图。真的是花了点时间才找到我生且亲生的那一枚小盆友...

  • 输入输出

    最近几天脚疼,行动不便,于是惰性有增加了。这几天输入少了输出也几乎没有。就连日记也是越写越少。 今天盆友在群里分享...

网友评论

      本文标题:60s倒计时(Q群里盆友分享的)

      本文链接:https://www.haomeiwen.com/subject/cirdjttx.html