引导页实现
Demo下载链接地址:https://github.com/tryingx/iPhone-IntroductionTutorial
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)viewWillAppear:(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 //Set delegate to self for callbacks (optional) 29 introductionView.delegate = self; 30 31 //STEP 3: Show introduction view 32 [introductionView showInView:self.view]; 33 34 //写入数据 35 NSUserDefaults * setting = [NSUserDefaults standardUserDefaults]; 36 NSString * key = [NSString stringWithFormat:@"is_first"]; 37 [setting setObject:[NSString stringWithFormat:@"false"] forKey:key]; 38 [setting synchronize]; 39 } 40 }
viewWillAppear是在视图即将显示时候调用的方法。 这里看头寻找沙盒中 is_first中是否有数据,如果没有,就说明是第一次运行程序,则显示引导页并且在沙盒对应位置写入数据。
如果有数据,就说明不是第一次运行,则跳过,不显示引导页。
激情为梦想而生