美圖鎮(zhèn)樓
首先這里使用的是SMSsdk短信驗證,如果用其他的更換即可
下面是點擊按鈕的事件,其中倒計時有點擊后的小動畫,自己去體會吧
<code>
-(void)SendCodeBut:(UIButton *)button{
if([self.MobileText.text compare:@""]==NSOrderedSame){
UIAlertView *alertV = [[UIAlertView alloc]initWithTitle:@"提示" message:@"手機號碼不能為空" delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];
[alertV show];
</code>
}else if(_MobileText.text.length<11){
<code>
UIAlertView alertV = [[UIAlertView alloc]initWithTitle:@"提示" message:@"手機號碼格式有誤,請輸入正確的號碼" delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];
[alertV show];
</code>
//手機號輸入正常,發(fā)送驗證碼并且啟動倒計時功能
}else if(_MobileText.text.length==11){
/*
@from v1.1.1
@brief 獲取驗證碼(Get verification code)
@param method 獲取驗證碼的方法(The method of getting verificationCode)
@param phoneNumber 電話號碼(The phone number)
@param zone 區(qū)域號僵井,不要加"+"號(Area code)
@param result 請求結(jié)果回調(diào)(Results of the request)
*/
<code>
[SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:self.MobileText.text zone:@"86" customIdentifier:nil result:^(NSError *error) {
</code>
if (error) {
NSLog(@"sada提交手機成功%@",error);
}else{
NSLog(@"sada提交手機成功");
<code>
__block int timeout=60; //倒計時時間
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){ //倒計時結(jié)束剖效,關(guān)閉
dispatch_source_cancel(_timer);
dispatch_async(dispatch_get_main_queue(), ^{
//設(shè)置界面的按鈕顯示 根據(jù)自己需求設(shè)置
[_sendCodeButton setTitle:@"發(fā)送驗證碼" forState:UIControlStateNormal];
_sendCodeButton.userInteractionEnabled = YES;
});
}
</code>
else{
<code>
int seconds = timeout % 60;
NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
dispatch_async(dispatch_get_main_queue(), ^{
//設(shè)置界面的按鈕顯示 根據(jù)自己需求設(shè)置
//NSLog(@"____%@",strTime);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[_sendCodeButton setTitle:[NSString stringWithFormat:@"重新發(fā)送(%@)",strTime] forState:UIControlStateNormal];
//文字自適應(yīng)
[_sendCodeButton sizeToFit];
[UIView commitAnimations];
_sendCodeButton.userInteractionEnabled = NO;
});
timeout--;
}
});
dispatch_resume(_timer);
}
}];
}
}
</code>
福利來啦
性感風
清新風