- 效果圖
- 倒計時定時器
使用的是GCD定時器 -- GCD定時器
- 防止惡意點擊
其中設(shè)置了倒計時時間記錄唆铐,無論是pop銷毀再重建着茸,還是殺掉進(jìn)程再啟動程序族扰,都會從之前的計時時間開始匿情,除非之前的計時任務(wù)結(jié)束扭倾。
防止某些用戶惡意操作诅需,多觸發(fā)發(fā)送驗證碼漾唉。
- 使用方法
// 初始化
// identify參數(shù)的作用是區(qū)別控件(不建議使用)。不同的identify會有不同的計時記錄堰塌,不需要時傳nil赵刑,全局發(fā)送驗證碼按鈕就會共享同一個計時記錄,防止惡意用戶蔫仙。
DPSendCodeButton *sendCodeButton = [[DPSendCodeButton alloc]initWithFrame:CGRectMake(100, 100, 100, 100) identify:@"LoginViewButton"];
//是否允許后臺計時
[sendCodeButton allowTimingAtBackgound:NO];
//添加點擊事件
[sendCodeButton addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview: sendCodeButton];
其他控件屬性設(shè)置與UIButton相同