码迷,mamicode.com
首页 > 其他好文 > 详细

实现软件版本新特性的具体步奏

时间:2014-06-10 11:34:52      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   a   

1、版本新特性:
     控制器的跳转不能使用push 和modal,
     push: 采用的时栈的方式,无法销毁之前的控制器
     modal:无法销毁之前的控制器
    应该使用rootViewController
2、实现过程:
    ①设置滚动视图,一般是整个界面
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<span style="color: rgb(0, 0, 255);">- (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<IWNewfeatureImageCount; index++) {
        UIImageView *imageView = [[UIImageView alloc] init];
         
        // 设置图片
        NSString *name = [NSString stringWithFormat:@"new_feature_%d", index + 1];
        imageView.image = [UIImage imageWithName:name];
         
        // 设置frame
        CGFloat imageX = index * imageW;
        imageView.frame = CGRectMake(imageX, 0, imageW, imageH);
         
        [scrollView addSubview:imageView];
         
        // 在最后一个图片上面添加按钮
        if (index == IWNewfeatureImageCount - 1) {
            [self setupLastImageView:imageView];
        }
    }
     
    // 3.设置滚动的内容尺寸
    scrollView.contentSize = CGSizeMake(imageW * IWNewfeatureImageCount, 0);
   // 取消水平滚动条 scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.pagingEnabled = YES;
// 取消滚动的弹簧效果  
  scrollView.bounces = NO;
}
</span>

        ②设置分页,求出分页的页码,需要使用UIScrollView的代理,使用代理方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 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;
}

    ③在最后一张图片添加按钮,跳转控制器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
- (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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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];
   }

 

实现软件版本新特性的具体步奏,布布扣,bubuko.com

实现软件版本新特性的具体步奏

标签:c   style   class   blog   code   a   

原文地址:http://www.cnblogs.com/angongIT/p/3779124.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!