最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS獲取短信驗(yàn)證碼倒計(jì)時(shí)的兩種實(shí)現(xiàn)方法

 更新時(shí)間:2017年05月18日 11:00:42   作者:APP叫我取個(gè)帥氣的昵稱  
本篇文章主要介紹了iOS獲取短信驗(yàn)證碼倒計(jì)時(shí)的兩種實(shí)現(xiàn)方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

方法一:

網(wǎng)上用的很多的一種,不多說,直接上代碼.

-(void)startTime{
  __block int timeout= 60; //倒計(jì)時(shí)時(shí)間
  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); //每秒執(zhí)行
  dispatch_source_set_event_handler(_timer, ^{
    if(timeout<=0){ //倒計(jì)時(shí)結(jié)束,關(guān)閉
      dispatch_source_cancel(_timer);
      dispatch_async(dispatch_get_main_queue(), ^{
        [self.getIdentifyCodeBt setTitle:@"獲取驗(yàn)證碼" forState:UIControlStateNormal];
        self.getIdentifyCodeBt.userInteractionEnabled = YES;
        [self.getIdentifyCodeBt setTitleColor:THEME_RED forState:UIControlStateNormal];
        self.getIdentifyCodeBt.backgroundColor = [UIColor whiteColor];
        self.getIdentifyCodeBt.layer.borderColor = THEME_RED.CGColor;
      });
    }else{
      dispatch_async(dispatch_get_main_queue(), ^{

        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:1];
        [self.getIdentifyCodeBt setTitle:[NSString stringWithFormat:@"%zd秒后失效",timeout] forState:UIControlStateNormal];
        [self.getIdentifyCodeBt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.getIdentifyCodeBt.backgroundColor = [UIColor lightGrayColor];
        self.getIdentifyCodeBt.layer.borderColor = [UIColor clearColor].CGColor;
        self.getIdentifyCodeBt.clipsToBounds = YES;
        [UIView commitAnimations];
        self.getIdentifyCodeBt.userInteractionEnabled = NO;
      });
      timeout--;
    }
  });
  dispatch_resume(_timer);

}

到時(shí)直接調(diào)用就可以了。

方法二:利用分類

給UIButton新建一個(gè)分類

.h文件如下

#import <UIKit/UIKit.h>

@interface UIButton (XSCountDown)
- (void)xs_beginCountDownWithDuration:(NSTimeInterval)duration;
- (void)xs_stopCountDown;
@end

.m文件如下

#import "UIButton+XSCountDown.h"

#import "ThemeColor.h"
static NSTimer *_countTimer;
static NSTimeInterval _count;
static NSString *_title;

@implementation UIButton (XSCountDown)

- (void)xs_beginCountDownWithDuration:(NSTimeInterval)duration {
  _title = self.titleLabel.text;
  _count = duration;
  _countTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(xs_updateTitle) userInfo:nil repeats:YES];
  [[NSRunLoop mainRunLoop] addTimer:_countTimer forMode:NSRunLoopCommonModes];
  self.userInteractionEnabled = NO;

   [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  self.backgroundColor = [UIColor lightGrayColor];
  self.layer.borderColor = [UIColor clearColor].CGColor;
  self.clipsToBounds = YES;
}

- (void)xs_stopCountDown {
  [_countTimer invalidate];
  _countTimer = nil;
  _count = 60.0;
  [self setTitle:_title forState:UIControlStateNormal];
  self.userInteractionEnabled = YES;
}

- (void)xs_updateTitle {
  NSString *countString = [NSString stringWithFormat:@"%lis 后失效", (long)_count - 1];
  self.userInteractionEnabled = NO;
  [self setTitle:countString forState:UIControlStateNormal];
  if (_count-- <= 1.0) {
    [self xs_stopCountDown];
    [self setTitleColor:THEME_RED forState:UIControlStateNormal];
    self.backgroundColor = [UIColor whiteColor];
    self.layer.borderColor = THEME_RED.CGColor;
  }

}

@end

然后在controller里直接調(diào)用分類.h文件里的方法就ok了

[self.verifyBt xs_beginCountDownWithDuration:60.0];

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • iOS導(dǎo)航欄對(duì)控制器view的影響詳解

    iOS導(dǎo)航欄對(duì)控制器view的影響詳解

    這篇文章主要給大家介紹了關(guān)于iOS導(dǎo)航欄對(duì)控制器view的影響的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)各位iOS開發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09
  • 基于iOS Realm數(shù)據(jù)庫(kù)的使用實(shí)例詳解

    基于iOS Realm數(shù)據(jù)庫(kù)的使用實(shí)例詳解

    下面小編就為大家分享一篇基于iOS Realm數(shù)據(jù)庫(kù)的使用實(shí)例詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01
  • iOS動(dòng)畫教你編寫Slack的Loading動(dòng)畫進(jìn)階篇

    iOS動(dòng)畫教你編寫Slack的Loading動(dòng)畫進(jìn)階篇

    這篇文章主要為大家進(jìn)一步詳細(xì)介紹了iOS動(dòng)畫教你編寫Slack的Loading動(dòng)畫,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • iOS面試中如何優(yōu)雅回答B(yǎng)lock導(dǎo)致循環(huán)引用的問題

    iOS面試中如何優(yōu)雅回答B(yǎng)lock導(dǎo)致循環(huán)引用的問題

    這篇文章主要給大家介紹了iOS面試中關(guān)于如何優(yōu)雅回答B(yǎng)lock導(dǎo)致循環(huán)引用的問題的相關(guān)資料,文中通過圖文介紹的非常相信,相信對(duì)大家具有一定的參考價(jià)值,需要的朋友們下面來一起看看吧。
    2017-03-03
  • iOS中視頻播放器的簡(jiǎn)單封裝詳解

    iOS中視頻播放器的簡(jiǎn)單封裝詳解

    要實(shí)現(xiàn)封裝視頻播放器,首先需要實(shí)現(xiàn)視頻播放器,然后再去考慮怎樣封裝可以讓以后自己使用起來方便快捷。iOS9之前可以使用MediaPlayer來進(jìn)行視頻的播放,iOS9之后系統(tǒng)推薦使用AVFoundation框架實(shí)現(xiàn)視頻的播放。下面通過本文來看看詳細(xì)的介紹吧。
    2016-10-10
  • iOS10 適配-Xcode8問題總結(jié)及解決方案

    iOS10 適配-Xcode8問題總結(jié)及解決方案

    這篇文章主要介紹了iOS10 適配-Xcode8問題總結(jié)的相關(guān)資料,這里整理了遇到的幾種問題,并給出解決方案,需要的朋友可以參考下
    2016-11-11
  • IOS開發(fā)基礎(chǔ)之二維數(shù)組詳解

    IOS開發(fā)基礎(chǔ)之二維數(shù)組詳解

    這篇文章主要介紹了IOS開發(fā)基礎(chǔ)之二維數(shù)組詳解的相關(guān)資料,需要的朋友可以參考下
    2017-04-04
  • iOS 驗(yàn)證碼按鈕倒計(jì)時(shí)功能

    iOS 驗(yàn)證碼按鈕倒計(jì)時(shí)功能

    在app注冊(cè)或者登錄需要驗(yàn)證碼的地方、為了避免短時(shí)間內(nèi)刷驗(yàn)證碼、往往會(huì)加上一層驗(yàn)證當(dāng)?shù)褂?jì)時(shí)結(jié)束后、可以重新獲取,關(guān)于ios 驗(yàn)證碼按鈕倒計(jì)時(shí)功能大家可以參考下本文
    2017-07-07
  • iOS消息發(fā)送和轉(zhuǎn)發(fā)示例詳解

    iOS消息發(fā)送和轉(zhuǎn)發(fā)示例詳解

    這篇文章主要給大家介紹了關(guān)于iOS消息發(fā)送和轉(zhuǎn)發(fā)的相關(guān)資料,用Objective-C的術(shù)語(yǔ)來講,這叫做“給某個(gè)對(duì)象發(fā)送某條消息”。文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-03-03
  • iOS左滑手勢(shì)失效的解決方法

    iOS左滑手勢(shì)失效的解決方法

    這篇文章主要為大家詳細(xì)介紹了iOS左滑手勢(shì)失效的解決方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-09-09

最新評(píng)論

轮台县| 贵德县| 固镇县| 邹城市| 永春县| 二连浩特市| 新昌县| 县级市| 隆回县| 汉源县| 汝州市| 荆州市| 新丰县| 龙陵县| 兰西县| 贵德县| 仙桃市| 张家口市| 堆龙德庆县| 昌吉市| 鄂州市| 桃园市| 呼图壁县| 云龙县| 天长市| 宁南县| 大新县| 新晃| 白水县| 铁岭市| 裕民县| 上饶市| 红原县| 庄浪县| 沁阳市| 乾安县| 南昌市| 大冶市| 建平县| 白山市| 瑞金市|