iOS實(shí)現(xiàn)啟動(dòng)引導(dǎo)頁(yè)與指紋解鎖的方法詳解_第1頁(yè)
iOS實(shí)現(xiàn)啟動(dòng)引導(dǎo)頁(yè)與指紋解鎖的方法詳解_第2頁(yè)
iOS實(shí)現(xiàn)啟動(dòng)引導(dǎo)頁(yè)與指紋解鎖的方法詳解_第3頁(yè)
iOS實(shí)現(xiàn)啟動(dòng)引導(dǎo)頁(yè)與指紋解鎖的方法詳解_第4頁(yè)
iOS實(shí)現(xiàn)啟動(dòng)引導(dǎo)頁(yè)與指紋解鎖的方法詳解_第5頁(yè)
已閱讀5頁(yè),還剩4頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

第iOS實(shí)現(xiàn)啟動(dòng)引導(dǎo)頁(yè)與指紋解鎖的方法詳解前言

應(yīng)用程序啟動(dòng)時(shí)有些會(huì)有引導(dǎo)頁(yè),目的是用戶第一次登錄時(shí)對(duì)應(yīng)用程序的一些簡(jiǎn)單了解介紹,一般就是幾張輪播圖片,當(dāng)引用程序第一次進(jìn)入時(shí)會(huì)跳到引導(dǎo)頁(yè),以后不再顯示,這時(shí)就需要將不是第一次登錄的標(biāo)致flag保存到內(nèi)存中,推薦用戶偏好設(shè)置NSUserDefaults,第一直接去取值取這個(gè)flag取不到(因?yàn)槭堑谝淮蔚卿?就跳引導(dǎo)頁(yè),然后在引導(dǎo)頁(yè)進(jìn)入登錄頁(yè)或者首頁(yè)時(shí)將flag值保存到偏好設(shè)置中,以后再進(jìn)來(lái)就可以取到不是第一登錄的flag就直接跳過(guò)引導(dǎo)頁(yè).方式有兩種:一種是直接切換UIWindow的根控制器本文是第一種,另一種是模態(tài)彈出,根據(jù)具體需求決定!

效果圖:

引導(dǎo)頁(yè)及指紋識(shí)別效果圖1

引導(dǎo)頁(yè)及指紋識(shí)別效果圖2

以下直接上代碼:

AppDelegate文件中

#importAppDelegate.h

#importGuidePagesViewController.h

#importLoginViewController.h

@interfaceAppDelegate()

@implementationAppDelegate

-(BOOL)application:(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions{

self.window=[[UIWindowalloc]initWithFrame:[UIScreenmainScreen].bounds];

self.window.backgroundColor=[UIColorwhiteColor];

NSUserDefaults*userDefault=[NSUserDefaultsstandardUserDefaults];

if(![userDefaultboolForKey:@isNotFirst]){//如果用戶是第一次登錄

self.window.rootViewController=[[GuidePagesViewControlleralloc]init];

}else{//否則直接進(jìn)入登錄頁(yè)面

self.window.rootViewController=[[LoginViewControlleralloc]init];

[self.windowmakeKeyAndVisible];

returnYES;

}

引導(dǎo)頁(yè)控制器:GuidePagesViewController

//GuidePagesViewController.m

//登錄引導(dǎo)頁(yè)開(kāi)發(fā)

//Createdbyhjon2025/1/31.

//Copyright2025年hj.Allrightsreserved.

#importGuidePagesViewController.h

#importLoginViewController.h

#defineScreenWidth[UIScreenmainScreen].bounds.size.width

#defineScreenHeight[UIScreenmainScreen].bounds.size.height

@interfaceGuidePagesViewController()UIScrollViewDelegate

@property(nonatomic,strong)UIScrollView*mainScrollV;

@property(nonatomic,strong)UIPageControl*pageControl;

@property(nonatomic,strong)NSMutableArray*images;

@implementationGuidePagesViewController

-(void)viewDidLoad{

[superviewDidLoad];

[self.viewaddSubview:self.mainScrollV];

[self.viewaddSubview:self.pageControl];

-(UIScrollView*)mainScrollV{

if(!_mainScrollV){

_mainScrollV=[[UIScrollViewalloc]initWithFrame:self.view.bounds];

_mainScrollV.bounces=NO;

_mainScrollV.pagingEnabled=YES;

_mainScrollV.showsHorizontalScrollIndicator=NO;

_mainScrollV.delegate=self;

_mainScrollV.contentSize=CGSizeMake(self.images.count*ScreenWidth,ScreenHeight);

[selfaddSubImageViews];

return_mainScrollV;

-(NSMutableArray*)images{

if(!_images){

_images=[NSMutableArrayarray];

NSArray*imageNames=@[@u1,@u2,@u3,@u4

for(NSString*nameinimageNames){

[self.imagesaddObject:[UIImageimageNamed:name]];

return_images;

-(void)addSubImageViews{

for(inti=0;iself.images.count;i++){

UIImageView*imageV=[[UIImageViewalloc]initWithFrame:CGRectMake(i*ScreenWidth,0,ScreenWidth,ScreenHeight)];

imageV.image=self.images[i];

[_mainScrollVaddSubview:imageV];

if(i==self.images.count-1){//最后一張圖片時(shí)添加點(diǎn)擊進(jìn)入按鈕

imageV.userInteractionEnabled=YES;

UIButton*btn=[UIButtonbuttonWithType:UIButtonTypeCustom];

btn.frame=CGRectMake(ScreenWidth*0.5-80,ScreenHeight*0.7,160,40);

[btnsetTitle:@點(diǎn)擊一下,你就知道forState:UIControlStateNormal];

[btnsetTitleColor:[UIColorwhiteColor]forState:UIControlStateNormal];

btn.backgroundColor=[UIColorredColor];

btn.layer.cornerRadius=20;

btn.layer.borderWidth=1;

btn.layer.borderColor=[UIColorredColor].CGColor;

[btnaddTarget:selfaction:@selector(btnClick)forControlEvents:UIControlEventTouchUpInside];

[imageVaddSubview:btn];

//點(diǎn)擊按鈕保存第一次登錄的標(biāo)記到本地并且跳入登錄界面

-(void)btnClick{

//保存標(biāo)記到本地

NSUserDefaults*userDef=[NSUserDefaultsstandardUserDefaults];

[userDefsetBool:YESforKey:@isNotFirst

[userDefsynchronize];

//切換視圖控制器

[UIApplicationsharedApplication].keyWindow.rootViewController=[[LoginViewControlleralloc]init];

-(UIPageControl*)pageControl{

if(!_pageControl){

_pageControl=[[UIPageControlalloc]initWithFrame:CGRectMake(ScreenWidth/self.images.count,ScreenHeight*15/16.0,ScreenWidth/2,ScreenHeight/16.0)];

//設(shè)置總頁(yè)數(shù)

_pageControl.numberOfPages=self.images.count;

//設(shè)置分頁(yè)指示器顏色

_pageControl.pageIndicatorTintColor=[UIColorblueColor];

//設(shè)置當(dāng)前指示器顏色

_pageControl.currentPageIndicatorTintColor=[UIColorredColor];

_pageControl.enabled=NO;

return_pageControl;

#pragmamarkUIScrollViewDelegate

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

self.pageControl.currentPage=(NSInteger)self.mainScrollV.contentOffset.x/ScreenWidth;

@end

指紋解鎖很簡(jiǎn)單,導(dǎo)入頭文件#importLocalAuthentication/LocalAuthentication.h,驗(yàn)證手機(jī)系統(tǒng)是否支持指紋解鎖iOS8以后才行,驗(yàn)證本手機(jī)是否開(kāi)啟了指紋識(shí)別,是否錄入了指紋等

指紋登錄驗(yàn)證:LoginViewController

//LoginViewController.m

//指紋驗(yàn)證

//Createdbyhjon2025/1/31.

//Copyright2025年hj.Allrightsreserved.

#importLoginViewController.h

#importLocalAuthentication/LocalAuthentication.h

@interfaceLoginViewController()

@implementationLoginViewController

-(void)viewDidLoad{

[superviewDidLoad];

if([UIDevicecurrentDevice].systemVersion.floatValue8.0){//8.0以后才支持指紋

return;

UIButton*btn=[UIButtonbuttonWithType:UIButtonTypeCustom];

btn.frame=CGRectMake(0,0,160,50);

btn.center=self.view.center;

[btnsetTitle:@點(diǎn)擊一下,指紋登錄forState:0];

[btnsetTitleColor:[UIColorredColor]forState:0];

btn.backgroundColor=[UIColoryellowColor];

btn.layer.borderColor=[UIColororangeColor].CGColor;

btn.layer.borderWidth=2;

btn.layer.cornerRadius=20;

[btnaddTarget:selfaction:@selector(btnClick)forControlEvents:UIControlEventTouchUpInside];

[self.viewaddSubview:btn];

-(void)btnClick{

[selffingerprintVerification];

-(void)fingerprintVerification

//創(chuàng)建LAContext

LAContext*context=[[LAContextalloc]init];

NSError*error=nil;

if([contextcanEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometricserror:error]){

//支持指紋驗(yàn)證

[contextevaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometricslocalizedReason:@請(qǐng)驗(yàn)證已有指紋reply:^(BOOLsuccess,NSError*error){

if(success){

//驗(yàn)證成功,主線程處理UI

NSLog(@成功啦

//用戶選擇輸入密碼,切換主線程處理

dispatch_async(dispatch_get_main_queue(),^{

[selfshowMessage:@指紋登錄成功!

else

NSLog(@%@,error.localizedDescription);

switch(error.code){

caseLAErrorSystemCancel:

[selfshowMessage:@系統(tǒng)取消授權(quán),如其他APP切入

//系統(tǒng)取消授權(quán),如其他APP切入

break;

caseLAErrorUserCancel:

//用戶取消驗(yàn)證TouchID

[selfshowMessage:@用戶取消驗(yàn)證TouchID

break;

caseLAErrorAuthenticationFailed:

//授權(quán)失敗

[selfshowMessage:@授權(quán)失敗

break;

caseLAErrorPasscodeNotSet:

//系統(tǒng)未設(shè)置密碼

[selfshowMessage:@系統(tǒng)未設(shè)置密碼

break;

caseLAErrorBiometryNotAvailable:

//設(shè)備TouchID不可用,例如未打開(kāi)

[selfshowMessage:@設(shè)備TouchID不可用,例如未打開(kāi)

break;

caseLAErrorBiometryNotEnrolled:

//設(shè)備TouchID不可用,用戶未錄入

[selfshowMessage:@設(shè)備TouchID不可用,用戶未錄入

break;

caseLAErrorUserFallback:

[[NSOperationQueuemainQueue]addOperationWithBlock:^{

//用戶選擇輸入密碼,切換主線程處理

[selfshowMessage:@用戶選擇輸入密碼,切換主線程處理

break;

default:

[[NSOperationQueuemainQueue]addOperationWithBlock:^{

//其他情況,切換主線程處理

[selfshowMessage:@其他情況,切

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論