zoukankan      html  css  js  c++  java
  • 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 }



  • 相关阅读:
    layui弹出层使用方法之最详解
    rem实现简单的响应式布局
    layui数据库查询及数据处理
    header头设置解决 “已拦截跨源请求:同源策略禁止读取位于 http://back/test/test 的远程资源。(原因:CORS 头缺少 'Access-Control-Allow-Origin')。”
    mysql多表联查
    centos 7 安装独立环境 tcp6占用80端口解决方法
    JS for_of遍历数组
    通过几张图搞定json数据处理
    MQTT Broker mosquitto
    前言
  • 原文地址:https://www.cnblogs.com/somethingWithiOS/p/6138061.html
Copyright © 2011-2022 走看看