美图镇楼
首先这里使用的是SMSsdk短信验证,如果用其他的更换即可
下面是点击按钮的事件,其中倒计时有点击后的小动画,自己去体会吧
-(void)SendCodeBut:(UIButton *)button{
if([self.MobileText.text compare:@""]==NSOrderedSame){
UIAlertView *alertV = [[UIAlertView alloc]initWithTitle:@"提示" message:@"手机号码不能为空" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertV show];
}else if(_MobileText.text.length<11){
UIAlertView alertV = [[UIAlertView alloc]initWithTitle:@"提示" message:@"手机号码格式有误,请输入正确的号码" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertV show];
//手机号输入正常,发送验证码并且启动倒计时功能
}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 区域号,不要加"+"号(Area code)
@param result 请求结果回调(Results of the request)
*/
[SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:self.MobileText.text zone:@"86" customIdentifier:nil result:^(NSError *error) {
if (error) {
NSLog(@"sada提交手机成功%@",error);
}else{
NSLog(@"sada提交手机成功");
__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); //每秒执行
dispatch_source_set_event_handler(_timer, ^{
if(timeout<=0){ //倒计时结束,关闭
dispatch_source_cancel(_timer);
dispatch_async(dispatch_get_main_queue(), ^{
//设置界面的按钮显示 根据自己需求设置
[_sendCodeButton setTitle:@"发送验证码" forState:UIControlStateNormal];
_sendCodeButton.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];
[_sendCodeButton setTitle:[NSString stringWithFormat:@"重新发送(%@)",strTime] forState:UIControlStateNormal];
//文字自适应
[_sendCodeButton sizeToFit];
[UIView commitAnimations];
_sendCodeButton.userInteractionEnabled = NO;
});
timeout--;
}
});
dispatch_resume(_timer);
}
}];
}
}
福利来啦
性感风
清新风