一般项目中都会出现新特性页面,比如第一次使用应用的时候,或者在应用设置里查看新特性的时候会出现。
这里,选择新建一个专门处理项目新特性的控制器,来完成功能。
首先是
NewFeaturesViewController.h
#import <UIKit/UIKit.h> typedef enum : NSInteger{ NewfeatureTypeFromeSetting, //从设置界面进入该页 NewfeatureTypeFromeWelcom, //第一次安装的时候进入 } NewFeatureType; @interface NewFeaturesViewController : UIViewController @property (nonatomic,assign) NewFeatureType newfeaturetype; @end
NewFeaturesViewController.m
#import "NewFeaturesViewController.h" #import "ViewController.h" #define DLNewfeatureImageCount 3 @interface NewFeaturesViewController ()<UIScrollViewDelegate> @property (nonatomic,weak) UIPageControl *pageControl; @end @implementation NewFeaturesViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [UIApplication sharedApplication].statusBarHidden = YES; [self setupScrollView]; [self setupPageControl]; } -(void)setupScrollView{ //1. UIScrollView *scrollView = [[UIScrollView alloc]init]; scrollView.frame = self.view.bounds; scrollView.bounces = NO; scrollView.delegate = self; [self.view addSubview:scrollView]; //2. CGFloat imageW = scrollView.bounds.size.width; CGFloat imageH = scrollView.bounds.size.height; for (int i = 0; i < DLNewfeatureImageCount; i ++) { //2.1 UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(i*imageW, 0, imageW, imageH)]; if (i == 0) { imgView.backgroundColor = [UIColor redColor]; } if (i == 1) { imgView.backgroundColor = [UIColor greenColor]; } if (i == 2) { imgView.backgroundColor = [UIColor blueColor]; [self setupLastImageView:imgView]; } [scrollView addSubview:imgView]; } scrollView.contentSize = CGSizeMake(DLNewfeatureImageCount * imageW, 0); scrollView.pagingEnabled = YES; } -(void)setupPageControl{ UIPageControl *pageC = [[UIPageControl alloc]init]; pageC.center = CGPointMake(self.view.frame.size.width*0.5, self.view.frame.size.height-20); pageC.numberOfPages = DLNewfeatureImageCount; [self.view addSubview:pageC]; self.pageControl = pageC; } -(void)setupLastImageView:(UIImageView *)imgView{ imgView.userInteractionEnabled = YES; UIButton *startButton = [[UIButton alloc] init]; startButton.frame = CGRectMake(0, imgView.frame.size.height-50, imgView.frame.size.width, 30); [imgView addSubview:startButton]; [startButton addTarget:self action:@selector(start) forControlEvents:UIControlEventTouchUpInside]; [startButton setTitle:@"立即开始" forState:UIControlStateNormal]; } -(void)start{ [UIApplication sharedApplication].statusBarHidden = NO; //判断类型 if (self.newfeaturetype == NewfeatureTypeFromeWelcom) { }else{ } ViewController *vc = [[ViewController alloc]init]; //切换控制器 UIWindow *window = [UIApplication sharedApplication].keyWindow; window.rootViewController = vc; } -(void)scrollViewDidScroll:(UIScrollView *)scrollView{ //1. CGFloat doublePage = scrollView.contentOffset.x / scrollView.frame.size.width; int intpage = (int)(doublePage + 0.5); NSLog(@"%d",intpage); self.pageControl.currentPage = intpage; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end
使用方法:
在AppDelegate中,将self.window.rootViewController 设置为本类,在点击“立即开始”按钮后,切换控制器为主体控制器。