当我们下载安装一个新的应用,或者将先用应用更新之后,第一次打开会又个启动滑动图,介绍程序的功能或增加的新特性.这个界面只在第一次打开时出现,之后就不再显示.此处利用程序版本号,以及UIScrollView和UipageControl实现程序启动滑动图.
程序启动时,最先打开的是入口类:AppDelegate,所以先在入口类中判断程序是否为第一次打开.
//获取当前版本号 NSString *key=(NSString *)kCFBundleVersionKey; NSString *version=[NSBundle mainBundle].infoDictionary[key]; //上次版本存储的版本号 NSString *saveVersion=[[NSUserDefaults standardUserDefaults]objectForKey:key]; //判断版本号是否一致,如果一致,跳转到主页 if ([version isEqualToString:saveVersion]) { mainViewController *main=[[mainViewController alloc]init]; UIWindow *window=[UIapplication sharedApplication].delegate.window; window.rootViewController=main; } //如果不一致,进入启动滑动页面 else { //在进入启动页面之前,先把新的版本号存入沙盒,替代旧版本号 [[NSUserDefaults standardUserDefaults]setObject:version forKey:key]; [[NSUserDefaults standardUserDefaults]synchronize]; scrollViewController *scroll=[[scrollViewController alloc]init]; UIWindow *window=[UIApplication sharedApplication].delegate.window; window.rootViewController=scroll; }
在启动滑动页面添加UIScorllVIew和UIPageControl
添加UIScrollView-(void)addScorll{ scroll=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)]; scroll.pagingEnabled=YES; //将scroll的大小设计的比原来多一点,目的是当滑动到最后一张图时,再次滑动会进入主界面,没有为什么,我自己试出来的. scroll.contentSize=CGSizeMake(320*3+150, 0); //添加图片 for (int i=0; i<3; i++) { UIImageView *image=[[UIImageView alloc]initWithFrame:CGRectMake(320*i, 0, 320, 480)]; image.image=[UIImage imageNamed:[NSString stringWithFormat:@"%d.png",i+1]]; [scroll addSubview:image]; //为每个页面添加跳过按钮 UIButton *jump=[UIButton buttonWithType:UIButtonTypeCustom]; jump.frame=CGRectMake(320*i+110, 430, 100, 30); jump.backgroundColor=[UIColor redColor]; [jump addTarget:self action:@selector(jumpToMain) forControlEvents:UIControlEventTouchUpInside]; [scroll addSubview:jump]; } scroll.showsHorizontalScrollIndicator=NO; scroll.contentOffset=CGPointMake(0, 0); scroll.delegate=self; [self.view addSubview:scroll];}
点击跳过按钮跳转到下一页
-(void)jumpToMain{ mainViewController *main=[[mainViewController alloc]init]; UIWindow *window=[UIApplication sharedApplication].delegate.window; window.rootViewController=main;}
添加pagecontrol
-(void)addpagecontrl{ page=[[UIPageControl alloc]init]; page.frame=CGRectMake(110, 470, 100, 10); page.numberOfPages=3; page.currentPage=0; [self.view addSubview:page];}
滑动页面
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ page.currentPage=scroll.contentOffset.x/320; //第三张图像向左需要滑动超过140才能跳转,这个随个人情况调吧 if (scroll.contentOffset.x>320*2+140) { mainViewController *main=[[mainViewController alloc]init]; UIWindow *window=[UIApplication sharedApplication].delegate.window; window.rootViewController=main; }}
新闻热点
疑难解答