短信倒計時和歡迎界面的Demo

1.短信倒計時的方法使用的是一個多線程的的倒計時的處理方法:(采用的是MOB的短信的哪個三方庫的東西)

__blockinttimeout =60;//倒計時時間修改關鍵字加__block

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

//設置界面的按鈕顯示根據自己需求設置

[self.codeBtnsetTitle:@"重新發送"forState:UIControlStateNormal];

self.codeBtn.userInteractionEnabled=YES;

});

}else{

intseconds = timeout %69;

NSString*strTime = [NSStringstringWithFormat:@"%.2d", seconds];

dispatch_async(dispatch_get_main_queue(), ^{

[self.codeBtnsetTitle:[NSStringstringWithFormat:@"%@s",strTime]forState:UIControlStateNormal];

[self.codeBtnsetTitleColor:GRAYCOLORforState:UIControlStateNormal];

self.codeBtn.userInteractionEnabled=NO;

});

timeout--;

}

});

dispatch_resume(_timer);

[SMSSDKgetVerificationCodeByMethod:SMSGetCodeMethodSMSphoneNumber:self.phoneTF.textzone:@"86"customIdentifier:nilresult:^(NSError*error) {

if(!error) {

DLog(@"獲取驗證碼成功");

}else{

NSString*errStr = [[NSStringalloc]init];

errStr = error.userInfo[@"getVerificationCode"];

[selfshowTips:errStrToView:self];

}

}];

得到驗證碼之后的話要驗證下驗證碼是否是確定的方法-==>

[SMSSDKcommitVerificationCode:self.codeTF.textphoneNumber:self.phoneTF.textzone:@"86"result:^(NSError*error) {

if(!error) {

NSLog(@"驗證成功");

//獲取短信的東西

[selfcheckPhone];

}else{

NSLog(@"錯誤信息:%@",error);

}

}];

到這里就可以直接使用了

2.歡迎界面的Demo代碼:

- (void)viewDidLoad {

[superviewDidLoad];

//setupScrollview

[selfsetupScollView];

//setupPageContol

[selfsetupPageControl];

//隱藏navbar

self.navigationController.navigationBarHidden=YES;

}

-(void)setupScollView{

UIScrollView*scrollview = [[UIScrollViewalloc]init];

scrollview.frame=self.view.bounds;

scrollview.delegate=self;

[self.viewaddSubview:scrollview];

//添加圖片

CGFloatimageW = scrollview.width;

CGFloatimageH = scrollview.height;

for(inti =0; i

UIImageView*imageView = [[UIImageViewalloc]init];

NSString*name = [NSStringstringWithFormat:@"welcome%d",i+1];

imageView.image= [UIImageimageNamed:name];

[scrollviewaddSubview:imageView];

UIButton*button = [[UIButtonalloc]init];

button.frame=CGRectMake(self.view.width*0.82,10,40,20);

[buttonsetTitle:@"跳過"forState:UIControlStateNormal];

[buttonaddTarget:selfaction:@selector(startExperience)forControlEvents:UIControlEventTouchUpInside];

button.titleLabel.font= [UIFontsystemFontOfSize:12];

button.alpha=0.6;

button.backgroundColor= [UIColorlightGrayColor];

imageView.userInteractionEnabled=YES;

[imageViewaddSubview:button];

//給最后一個imageview添加一個圖片

if(i ==EVNewFeatureImageVieCount-1) {

[selfsetupLastImageView:imageView];

[buttonremoveFromSuperview];

}

imageView.y=0;

imageView.width= imageW;

imageView.height= imageH;

imageView.x= i * imageW;

}

//設置屬性

scrollview.contentSize=CGSizeMake(EVNewFeatureImageVieCount* imageW,0);

scrollview.pagingEnabled=YES;

scrollview.showsHorizontalScrollIndicator=NO;

scrollview.backgroundColor=RGBCOLOR(246,246,246);

}

-(void)setupPageControl{

UIPageControl*pageControl = [[UIPageControlalloc]init];

pageControl.numberOfPages=EVNewFeatureImageVieCount;

pageControl.centerX=self.view.width*0.5;

pageControl.centerY=self.view.height-30;

pageControl.currentPageIndicatorTintColor= [UIColorredColor];

pageControl.pageIndicatorTintColor= [UIColorlightGrayColor];

[self.viewaddSubview:pageControl];

self.pageControl= pageControl;

}

//給加上一個image

-(void)setupLastImageView:(UIImageView*)imageView{

imageView.userInteractionEnabled=YES;

//添加開始按鈕了

[selfsetupStartButton:imageView];

}

-(void)setupStartButton:(UIImageView*)imageView{

UIButton*startButton = [[UIButtonalloc]init];

[imageViewaddSubview:startButton];

startButton.backgroundColor=RGBCOLOR(2,152,221);

//設置frame

startButton.size=CGSizeMake(70,25);

startButton.centerX=self.view.width*0.5;

startButton.centerY=self.view.height*0.86;

//設置按鈕興致,描邊

startButton.layer.cornerRadius=10/3;

startButton.layer.borderColor= [[UIColorwhiteColor]CGColor];

startButton.layer.borderWidth=1.2;

startButton.layer.masksToBounds=YES;

//設置文字

[startButtonsetTitle:@"開始體驗"forState:UIControlStateNormal];

startButton.titleLabel.font= [UIFontsystemFontOfSize:13];

[startButtonsetTitleColor:[UIColorwhiteColor]forState:UIControlStateNormal];

[startButtonaddTarget:selfaction:@selector(startExperience)forControlEvents:UIControlEventTouchUpInside];

}

//開始廣告頁

-(void)startExperience{

ZFLoginViewController*loginVC = [[ZFLoginViewControlleralloc]init];

[self.navigationControllerpushViewController:loginVCanimated:YES];

//第一次的東西

BOOLnotFrist =YES;

[[NSUserDefaultsstandardUserDefaults]setBool:notFristforKey:@"isFirst"];

[[NSUserDefaultsstandardUserDefaults]synchronize];

}

#pragma mark - UIScrollviewDelegate

-(void)scrollViewDidScroll:(UIScrollView*)scrollView{

//獲取頁碼

CGFloatdoublePage = scrollView.contentOffset.x/scrollView.width;

intintPage = (int)(doublePage +0.5);

//設置頁碼

self.pageControl.currentPage= intPage;

}

3.廣告界面Demo代碼:

待續。。。。。。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容