上午看到了一个APP的引导页,觉得很不错,当然对于一个编程的人来说,引导页当人不陌生啦;一般常见的也就是左右滑动,还有动画,视频什么的,设计的越来越五花八门啦,不过今天就来说一下最简单的滑动,SCrollowView;
第一步:首先创建一个集成自UIScrollView的类;
在.m文件中进行布局,比如我们今天举得例子有4张图片,那么实现的代码就如下:
-(instancetype)initWithFrame:(CGRect)frame{
self=[super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor whiteColor];
[self setContentSize:CGSizeMake(SCREEN_WIDTH * ([IMAGENAME(@"qwe") length]>3?4:5), SCREEN_HEIGHT)];
self.showsHorizontalScrollIndicator = NO;
self.delegate = self;
self.pagingEnabled=YES;
for (int i = 0; i <4) ; i++) {
UIImageView * yindaoBackImageView = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH * i, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
yindaoBackImageView.backgroundColor = [UIColor clearColor];
NSString * yindaoImageString = [[NSString alloc] initWithFormat:@"%@%d",IMAGENAME(@"yindao"),i + 1];
yindaoBackImageView.userInteractionEnabled = YES;
yindaoBackImageView.image = GETIMAGE(yindaoImageString);
[self addSubview:yindaoBackImageView];
}
}
return self;
}
第二步:就是滑动到最后一页进入应用程序,直接让其隐藏就好;
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
if(scrollView.contentOffset.x > SCREEN_WIDTH * 4 + 80){
self.hidden = YES;
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"yindaoye"];
这一步是为了再一次进入程序,判断其是第一次还是非第一次,在程序的入口会用到
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
第三步:也就是第二步注释的原因:
在程序的入口处: 如果还没有,就把引导页添加到程序中
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"yindaoye"]) {
YindaoView * yindaoScrollView=[[YindaoView alloc]initWithFrame:self.view.bounds];
[self.view addSubview:yindaoScrollView];
}