源碼: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
- //
- // mainView.h
- // softwareApp
- //
- // Created by 余龍澤 on 13-9-27.
- // Copyright (c) 2013年 余龍澤. All rights reserved.
- //
- #import <UIKit/UIKit.h>
- #import "MYIntroductionView.h"
- @interface mainView : UITabBarController<MYIntroductionDelegate>
- @end
3.在主界面對應的.m文件中加入如下代碼。
如我的mainView.m
- -(void)viewDidAppear:(BOOL)animated{
- //讀取沙盒數據
- NSUserDefaults * settings1 = [NSUserDefaults standardUserDefaults];
- NSString *key1 = [NSString stringWithFormat:@"is_first"];
- NSString *value = [settings1 objectForKey:key1];
- if (!value) //如果沒有數據
- {
- //STEP 1 Construct Panels
- 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!"];
- //You may also add in a title for each panel
- MYIntroductionPanel *panel2 = [[MYIntroductionPanel alloc] initWithimage:[UIImage imageNamed:@"SampleImage2"] title:@"Your Ticket!" description:@"MYIntroductionView is your ticket to a great tutorial or introduction!"];
- //STEP 2 Create IntroductionView
- /*A standard version*/
- //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]];
- /*A version with no header (ala "Path")*/
- //MYIntroductionView *introductionView = [[MYIntroductionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) panels:@[panel, panel2]];
- /*A more customized version*/
- 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];
- [introductionView setBackgroundImage:[UIImage imageNamed:@"SampleBackground"]];
- //Set delegate to self for callbacks (optional)
- introductionView.delegate = self;
- //STEP 3: Show introduction view
- [introductionView showInView:self.view];
- //寫入數據
- NSUserDefaults * setting = [NSUserDefaults standardUserDefaults];
- NSString * key = [NSString stringWithFormat:@"is_first"];
- [setting setObject:[NSString stringWithFormat:@"false"] forKey:key];
- [setting synchronize];
- }
- }
代碼不難。
viewDidAppear是在視圖即將顯示時候調用的方法。 這里看頭尋找沙盒中 is_first中是否有數據,如果沒有,就說明是第一次運行程序,則顯示引導頁並且在沙盒對應位置寫入數據。
如果有數據,就說明不是第一次運行,則跳過,不顯示引導頁。
很簡單的操作。當然有更好的方法,也有更好的類庫,這只是我個人選擇的方法罷了。