您的位置:首页 > 移动开发 > IOS开发

iOS 如何添加引导页

2015-11-02 16:41 543 查看
[objc] view
plaincopy





//这是直接在AppDelegate里写的

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

// Override point for customization after application launch.

self.window.backgroundColor = [UIColor whiteColor];

isOut =NO;

//在沙盒做一个文件,判断沙盒有没有这个文件

NSFileManager *manager=[NSFileManager defaultManager];

BOOL isHasFile=[manager fileExistsAtPath:[NSHomeDirectory() stringByAppendingString:@"aa.txt"]];

if (isHasFile) {

[self gotoMain]; //为真表示已有文件 曾经进入过主页

}else{

[self makeLaunchView];//为假表示没有文件,没有进入过主页

}

[self.window makeKeyAndVisible];

return YES;

}

[objc] view
plaincopy





//假引导页面

-(void)makeLaunchView{

NSArray *arr=[NSArray arrayWithObjects:@"helpphoto_one.png",@"helpphoto_two.png",@"helpphoto_three.png",@"helpphoto_four.png",@"helpphoto_five.png", nil nil];//数组内存放的是我要显示的假引导页面图片

//通过scrollView 将这些图片添加在上面,从而达到滚动这些图片

UIScrollView *scr=[[UIScrollView alloc] initWithFrame:self.window.bounds];

scr.contentSize=CGSizeMake(320*arr.count, self.window.frame.size.height);

scr.pagingEnabled=YES;

scr.tag=7000;

scr.delegate=self;

[self.window addSubview:scr];

for (int i=0; i<arr.count; i++) {

UIImageView *img=[[UIImageView alloc] initWithFrame:CGRectMake(i*320, 0, 320, self.window.frame.size.height)];

img.image=[UIImage imageNamed:arr[i]];

[scr addSubview:img];

[img release];

}

}

#pragma mark scrollView的代理

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

//这里是在滚动的时候判断 我滚动到哪张图片了,如果滚动到了最后一张图片,那么

//如果在往下面滑动的话就该进入到主界面了,我这里利用的是偏移量来判断的,当

//一共五张图片,所以当图片全部滑完后 又像后多滑了30 的时候就做下一个动作

if (scrollView.contentOffset.x>4*320+30) {

isOut=YES;//这是我声明的一个全局变量Bool 类型的,初始值为no,当达到我需求的条件时将值改为yes

}

}

//停止滑动

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

//判断isout为真 就要进入主界面了

if (isOut) {

//这里添加了一个动画,(可根据个人喜好)

[UIView animateWithDuration:1.5 animations:^{

scrollView.alpha=0;//让scrollview 渐变消失

}completion:^(BOOL finished) {

[scrollView removeFromSuperview];//将scrollView移除

[self gotoMain];//进入主界面

} ];

}

}

//去主页

-(void)gotoMain{

//如果第一次进入没有文件,我们就创建这个文件

NSFileManager *manager=[NSFileManager defaultManager];

//判断 我是否创建了文件,如果没创建 就创建这个文件(这种情况就运行一次,也就是第一次启动程序的时候)

if (![manager fileExistsAtPath:[NSHomeDirectory() stringByAppendingString:@"aa.txt"]]) {

[manager createFileAtPath:[NSHomeDirectory() stringByAppendingString:@"aa.txt"] contents:nil attributes:nil];

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: