1、版本新特性:
控制器的跳转不能使用push 和modal,
push: 采用的时栈的方式,无法销毁之前的控制器
modal:无法销毁之前的控制器
应该使用rootViewController
2、实现过程:
①设置滚动视图,一般是整个界面
- (void)setupScrollView{ UIScrollView *scrollView = [[UIScrollView alloc] init]; scrollView.frame = self.view.bounds; scrollView.delegate = self; [self.view addSubview:scrollView]; // 2.添加图片 CGFloat imageW = scrollView.frame.size.width; CGFloat imageH = scrollView.frame.size.height; for (int index = 0; index
②设置分页,求出分页的页码,需要使用UIScrollView的代理,使用代理方法
// 1.添加 UIPageControl *pageControl = [[UIPageControl alloc] init]; pageControl.numberOfPages = IWNewfeatureImageCount; CGFloat centerX = self.view.frame.size.width * 0.5; CGFloat centerY = self.view.frame.size.height - 30; pageControl.center = CGPointMake(centerX, centerY); pageControl.bounds = CGRectMake(0, 0, 100, 30); pageControl.userInteractionEnabled = NO; [self.view addSubview:pageControl]; self.pageControl = pageControl; // 2.设置圆点的颜色 pageControl.currentPageIndicatorTintColor = IWColor(253, 98, 42); pageControl.pageIndicatorTintColor = IWColor(189, 189, 189);②求出分页的页码,需要使用UIScrollView的代理,使用代理方法/** * 只要UIScrollView滚动了,就会调用 * */- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ // 1.取出水平方向上滚动的距离 CGFloat offsetX = scrollView.contentOffset.x; // 2.求出页码 double pageDouble = offsetX / scrollView.frame.size.width; int pageInt = (int)(pageDouble + 0.5); self.pageControl.currentPage = pageInt;}
③在最后一张图片添加按钮,跳转控制器
- (void)setupLastImageView:(UIImageView *)imageView{ // 0.让imageView能跟用户交互 imageView.userInteractionEnabled = YES; // 1.添加开始按钮 UIButton *startButton = [[UIButton alloc] init]; [startButton setBackgroundImage:[UIImage imageWithName:@"new_feature_finish_button"] forState:UIControlStateNormal]; [startButton setBackgroundImage:[UIImage imageWithName:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted]; // 2.设置frame CGFloat centerX = imageView.frame.size.width * 0.5; CGFloat centerY = imageView.frame.size.height * 0.6; startButton.center = CGPointMake(centerX, centerY); startButton.bounds = (CGRect){CGPointZero, startButton.currentBackgroundImage.size}; // 3.设置文字 [startButton setTitle:@"开始使用" forState:UIControlStateNormal]; [startButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [startButton addTarget:self action:@selector(start) forControlEvents:UIControlEventTouchUpInside]; [imageView addSubview:startButton]; // 4.添加checkbox UIButton *checkbox = [[UIButton alloc] init]; checkbox.selected = YES; [checkbox setTitle:@"分享给大家" forState:UIControlStateNormal]; [checkbox setImage:[UIImage imageWithName:@"new_feature_share_false"] forState:UIControlStateNormal]; [checkbox setImage:[UIImage imageWithName:@"new_feature_share_true"] forState:UIControlStateSelected]; checkbox.bounds = CGRectMake(0, 0, 200, 50); CGFloat checkboxCenterX = centerX; CGFloat checkboxCenterY = imageView.frame.size.height * 0.5; checkbox.center = CGPointMake(checkboxCenterX, checkboxCenterY); [checkbox setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; checkbox.titleLabel.font = [UIFont systemFontOfSize:15]; [checkbox addTarget:self action:@selector(checkboxClick:) forControlEvents:UIControlEventTouchUpInside]; checkbox.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10); [imageView addSubview:checkbox];}④点击开始使用时候,切换根控制器- (void)start{ // 显示状态栏 [UIApplication sharedApplication].statusBarHidden = NO; // 切换窗口的根控制器 self.view.window.rootViewController = [[IWTabBarViewController alloc] init];}
④利用沙盒,将使用的软件版本号与沙盒中存储的版本号进行对比,高于原版本就跳转到 IWNewfeatureViewController ,相同就跳转到IWTabBarViewController:
NSString *key = @"CFBundleVersion"; // 取出沙盒中存储的上次使用软件的版本号 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *lastVersion = [defaults stringForKey:key]; // 获得当前软件的版本号 NSString *currentVersion = [NSBundle mainBundle].infoDictionary[key]; if ([currentVersion isEqualToString:lastVersion]) { // 显示状态栏 application.statusBarHidden = NO; self.window.rootViewController = [[IWTabBarViewController alloc] init]; } else { // 新版本 self.window.rootViewController = [[IWNewfeatureViewController alloc] init]; // 存储新版本 [defaults setObject:currentVersion forKey:key]; [defaults synchronize]; }