iOS新特性引導頁

碼鋒窩發表於2016-12-06

有一個注意點:

獲取版本號
個叫做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 }

 



 

相關文章