一开始需要判断是否是第一次运行软件,如果是的话出现滚动视图,否则不出现。而且通常滚动驶入最后一页会有一个“开始体验”的按钮,点击后进入主界面。实例代码如下:
#import
@interface ViewController : UIViewController<UIScrollViewDelegate>
//滚动视图
@property (retain, nonatomic) UIScrollView *scView;
//滚动视图pageControl
@property (retain,nonatomic) UIPageControl *pageContrl;
//滚动视图最后一页“开始体验”按钮
@property (retain,nonatomic) UIButton *startBtn;
//文件管理器
@property (retain,nonatomic) NSFileManager *fileManager;
//判断app所在文件路径是否存在isFirst文件夹
@property (copy,nonatomic) NSString *newFolderPath;
@end
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//判断是否是程序第一次运行,若不是则不出现使用说明
if ([self.fileManager fileExistsAtPath:self.newFolderPath])
{
//创建滚动视图
self.scView=[[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)]autorelease];
//定义滚动视图的大小
self.scView.contentSize=CGSizeMake(320*5, 460);
//将图片加载到滚动视图
for (int i=0; i<<span style="color: #272ad8">5; i++)
{
NSString *str=[NSString stringWithFormat:@"fu%d.jpg",i+1];
UIImage *img=[UIImage imageNamed:str];
UIImageView *imgView=[[[UIImageView alloc]initWithImage:img]autorelease];
//设置滚动视图中每张图片的位置
imgView.frame=CGRectMake(i*320, 0, 320, 460);
//添加图片到滚动视图
[self.scView addSubview:imgView];
}
//每次只能拉动一张
self.scView.pagingEnabled=YES;
//滚动视图横向滚动条
self.scView.showsHorizontalScrollIndicator=YES;
//纵向滚动条
self.scView.showsVerticalScrollIndicator=NO;
//滚动视图指示器类型
self.scView.indicatorStyle=UIScrollViewIndicatorStyleDefault;
//拖动惯性设为NO
self.scView.bounces=NO;
//创建pageControl,添加底下的小圆点,告诉用户当前是滚动视图的第几页
self.pageContrl=[[[UIPageControl alloc]initWithFrame:CGRectMake(0, 400, 320, 20)]autorelease];
//添加到根视图,不能添加到滚动视图
[self.view addSubview:self.pageContrl];
//设置几个小点
self.pageContrl.numberOfPages=5;
//设置代理,执行UIScrollViewDelegate协议方法
self.scView.delegate=self;
[self.mapView addSubview:self.scView];
}
}
//滚动视图代理方法
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
//偏移(0,0)点多大的宽度,320一张,当滚动到第二页的时候,偏移量=320
CGPoint point=scrollView.contentOffset;
//获取滚动视图的当前页面,默认为0;
self.pageContrl.currentPage=point.x/320;
if (self.pageContrl.currentPage==4)
{
//最后一页添加一个“开始体验”按钮,点击该按钮进入主页面
UIButton *startBtn=[UIButton buttonWithType:UIButtonTypeCustom];
// [startBtn setTitle:@"开始体验" forState:UIControlStateNormal];
//设置按钮位置,第五页,前面要加上4*320
startBtn.frame=CGRectMake(1370, 360, 180, 50);
self.startBtn=startBtn;
//添加按钮点击事件
[self.startBtn addTarget:self action:@selector(startBtnAction:) forControlEvents:UIControlEventTouchDown];
//添加按钮
[self.scView addSubview:startBtn];
}
}
-(void) startBtnAction:(UIButton *) sender
{
//移除滚动视图
[self.scView removeFromSuperview];
//移除pageControl
[self.pageContrl removeFromSuperview];
//获取Application.h文件路径
NSString *rootPath=NSHomeDirectory();
NSLog(@"根目录为:%@",rootPath);
//创建文件管理器
self.fileManager = [NSFileManager defaultManager];
if ([self.fileManager fileExistsAtPath:rootPath])
{
self.newFolderPath=[NSString stringWithFormat:@"%@/isFirst",rootPath];
//在指定路径下创建isFirst文件夹
[self.fileManager createDirectoryAtPath:self.newFolderPath withIntermediateDirectories:YES attributes:nil error:nil];
NSLog(@"isFirst文件夹已创建");
}
}
//判断是否是程序第一次运行,若不是则不出现使用说明