ios滚动视图(scrollView)

注释详细 转了 谢谢
通常第一次运行软件时,会出现使用说明。或者软件更新升级有新功能的话,也会出现提示告诉你有哪些新功能,这些就是 滚动视图
一开始需要判断是否是第一次运行软件,如果是的话出现滚动视图,否则不出现。而且通常滚动驶入最后一页会有一个“开始体验”的按钮,点击后进入主界面。实例代码如下:

#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

{

    //偏移(00)点多大的宽度,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文件夹已创建");

    }    

}




// 判断是否是程序第一次运行,若不是则不出现使用说明
[转载]ios滚动视图(scrollView)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值