首页 > 代码库 > iOS新特性引导页

iOS新特性引导页

有一个注意点:

获取版本号
个叫做Version,一个叫做Build,这两个值都可以在Xcode 中选中target,点击“Summary”后看到。 Version在plist文件中的key是“CFBundleShortVersionString”,和AppStore上的版本号保持一致,Build在plist中的key是“CFBundleVersion”,代表build的版本号,该值每次build之后都应该增加1。这两个值都可以在程序中通过下面的代码获得:
 
1.Version
NSString *key = @"CFBundleShortVersionString";
2.build
NSString *key =@"CFBundleVersion";

 

1.在AppDelegate.m

 1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 2     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
 3 
 4     self.window.backgroundColor = [UIColor whiteColor];
 5 
 6     NSString *key = @"CFBundleShortVersionString";
 7     //上一个版本号,存沙盒
 8     NSString *lastVersion = [[NSUserDefaults standardUserDefaults] objectForKey:key];
 9     //当前版本号
10     NSString *currentVersion = [NSBundle mainBundle].infoDictionary[key];
11     NSLog(@"前面%@----当前%@",lastVersion,currentVersion);
12     
13     if ([currentVersion isEqualToString:lastVersion]) {
14         self.window.rootViewController = [ViewController new]; //为真表示已有文件 曾经进入过主页
15     }else{
16         self.window.rootViewController =[LGFNEWfeatureViewController new];//为假表示没有文件,没有进入过主页
17         [[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:key];
18         [[NSUserDefaults standardUserDefaults] synchronize];
19     }
20     [self.window makeKeyAndVisible];
21     
22     return YES;
23 }

 

2.在新特性的VC中:

 1 #import "LGFNEWfeatureViewController.h"
 2 #import "ViewController.h"
 3 
 4 #define LGFNEWFeatureCount 3
 5 @interface LGFNEWfeatureViewController ()<UIScrollViewDelegate>
 6 @property(nonatomic,strong)UIScrollView *scrollView;
 7 
 8 @property(nonatomic,strong)UIPageControl *pageControl;
 9 
10 @end
11 
12 @implementation LGFNEWfeatureViewController
13 
14 - (void)viewDidLoad {
15     [super viewDidLoad];
16     // Do any additional setup after loading the view.
17     [self setScrollerView];
18 }
19 
20 -(void)setScrollerView{
21     self.scrollView = [UIScrollView new];
22     _scrollView.frame = self.view.bounds;
23     _scrollView.contentSize = CGSizeMake(LGFNEWFeatureCount *self.view.frame.size.width, 0);
24     _scrollView.bounces = NO;
25     _scrollView.pagingEnabled = YES;
26     _scrollView.showsHorizontalScrollIndicator =NO;
27     [self.view addSubview:_scrollView];
28     for (int i =0; i<LGFNEWFeatureCount; i++) {
29         UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width*i, 0, self.view.frame.size.width, self.view.frame.size.height)];
30         imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d",i+1]];
31         [_scrollView addSubview:imageView];
32         if (i == LGFNEWFeatureCount-1) {
33             [self setupLastImageView:imageView];
34         }
35     }
36     _scrollView.delegate = self;
37     
38     self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(20, self.view.frame.size.height-30, self.view.frame.size.width-30,30)];
39     _pageControl.numberOfPages = LGFNEWFeatureCount;
40     _pageControl.currentPageIndicatorTintColor =[UIColor orangeColor];
41     _pageControl.userInteractionEnabled = NO;
42     [self.view addSubview:_pageControl];
43     
44 }
45 
46 -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
47     self.pageControl.currentPage = self.scrollView.contentOffset.x/self.view.frame.size.width;
48 }
49 
50 
51 -(void)setupLastImageView:(UIImageView*)imageView{
52     //开启用户交互
53     imageView.userInteractionEnabled = YES;
54     //1.分享
55     UIButton *sharedBtn =[[UIButton alloc] initWithFrame:CGRectMake(80, self.view.frame.size.height-210, self.view.frame.size.width*0.5,self.view.frame.size.height*0.3)];
56     
57     [sharedBtn setImage:[UIImage imageNamed:@"shared"] forState:UIControlStateNormal];
58      [sharedBtn setImage:[UIImage imageNamed:@"sharedselect"] forState:UIControlStateSelected];
59     [sharedBtn setTitle:@"分享给大家" forState:UIControlStateNormal];
60     sharedBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);
61     sharedBtn.titleLabel.font = [UIFont systemFontOfSize:18];
62     [sharedBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
63     [sharedBtn addTarget:self action:@selector(sharedBtnClick:) forControlEvents:UIControlEventTouchUpInside];
64     [imageView addSubview:sharedBtn];
65     
66     //2.开始程序首页
67     UIButton *startBtn = [[UIButton alloc] initWithFrame:CGRectMake(120, self.view.frame.size.height*0.88, self.view.frame.size.width*0.4,self.view.frame.size.height*0.05)];
68     startBtn.layer.cornerRadius = 12.0f;
69     startBtn.layer.masksToBounds =YES;
70     startBtn.backgroundColor = [UIColor orangeColor];
71     [startBtn setTitle:@"开启APP之旅" forState:UIControlStateNormal];
72     [startBtn addTarget:sharedBtn action:@selector(startBtnClick) forControlEvents:UIControlEventTouchUpInside];
73     [imageView addSubview:startBtn];
74     
75 }
76 
77 -(void)sharedBtnClick:(UIButton *)sharedBtn{
78     sharedBtn.selected = !sharedBtn.selected;
79 }
80 
81 -(void)startBtnClick{
82     UIWindow *win =[UIApplication sharedApplication].keyWindow;
83     win.rootViewController = [ViewController new];
84 }

 



 

iOS新特性引导页