ios開發-引導頁實現


源碼:http://files.cnblogs.com/ios8/%5Bcode4app.com%5DIntroductionTutorialView_10843.zip

可以看看demo,很簡單,我也是一看就懂。

下面說說我整合到我的項目中的方法。

 

1.把下載的demo中的

MYIntroductionView.h    

MYIntroductionView.m

MYIntroductionPanel.h

MYIntroductionPanel.m

這四個文件,再加上一些圖像資源加到你的工程中去。(之后如果要修改圖像等資源只要在相應位置修改就好了。這里只是師范,沒做修改)。

 

2.在你的主界面(打開應用顯示的第一個界面)

在對應的.h文件中引入頭文件並且設置協議。

如我的是  mainView.h

 
  1. //  
  2. //  mainView.h  
  3. //  softwareApp  
  4. //  
  5. //  Created by 余龍澤 on 13-9-27.  
  6. //  Copyright (c) 2013年 余龍澤. All rights reserved.  
  7. //  
  8.   
  9. #import <UIKit/UIKit.h>  
  10. #import "MYIntroductionView.h"  
  11.   
  12. @interface mainView : UITabBarController<MYIntroductionDelegate>  
  13.   
  14. @end  



 

3.在主界面對應的.m文件中加入如下代碼。

如我的mainView.m

 
  1. -(void)viewDidAppear:(BOOL)animated{  
  2.       
  3.     //讀取沙盒數據  
  4.     NSUserDefaults * settings1 = [NSUserDefaults standardUserDefaults];  
  5.     NSString *key1 = [NSString stringWithFormat:@"is_first"];  
  6.     NSString *value = [settings1 objectForKey:key1];  
  7.     if (!value)  //如果沒有數據  
  8.     {  
  9.         //STEP 1 Construct Panels  
  10.         MYIntroductionPanel *panel = [[MYIntroductionPanel alloc] initWithimage:[UIImage imageNamed:@"SampleImage1"] description:@"Welcome to MYIntroductionView, your 100 percent customizable interface for introductions and tutorials! Simply add a few classes to your project, and you are ready to go!"];  
  11.           
  12.         //You may also add in a title for each panel  
  13.         MYIntroductionPanel *panel2 = [[MYIntroductionPanel alloc] initWithimage:[UIImage imageNamed:@"SampleImage2"] title:@"Your Ticket!" description:@"MYIntroductionView is your ticket to a great tutorial or introduction!"];  
  14.           
  15.         //STEP 2 Create IntroductionView  
  16.           
  17.         /*A standard version*/  
  18.         //MYIntroductionView *introductionView = [[MYIntroductionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) headerImage:[UIImage imageNamed:@"SampleHeaderImage.png"] panels:@[panel, panel2]];  
  19.           
  20.           
  21.         /*A version with no header (ala "Path")*/  
  22.         //MYIntroductionView *introductionView = [[MYIntroductionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) panels:@[panel, panel2]];  
  23.           
  24.         /*A more customized version*/  
  25.         MYIntroductionView *introductionView = [[MYIntroductionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) headerText:@"MYIntroductionView" panels:@[panel, panel2] languageDirection:MYLanguageDirectionLeftToRight];  
  26.         [introductionView setBackgroundImage:[UIImage imageNamed:@"SampleBackground"]];  
  27.           
  28.           
  29.         //Set delegate to self for callbacks (optional)  
  30.         introductionView.delegate = self;  
  31.           
  32.         //STEP 3: Show introduction view  
  33.         [introductionView showInView:self.view];  
  34.           
  35.         //寫入數據  
  36.         NSUserDefaults * setting = [NSUserDefaults standardUserDefaults];  
  37.         NSString * key = [NSString stringWithFormat:@"is_first"];  
  38.         [setting setObject:[NSString stringWithFormat:@"false"] forKey:key];  
  39.         [setting synchronize];  
  40.     }  
  41. }  



 

代碼不難。

viewDidAppear是在視圖即將顯示時候調用的方法。 這里看頭尋找沙盒中 is_first中是否有數據,如果沒有,就說明是第一次運行程序,則顯示引導頁並且在沙盒對應位置寫入數據。

如果有數據,就說明不是第一次運行,則跳過,不顯示引導頁。  

 

很簡單的操作。當然有更好的方法,也有更好的類庫,這只是我個人選擇的方法罷了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM