引导页

判断版本号

// 创始字符串
    NSString *path = [[NSBundle mainBundle] pathForResource:@"Info.plist" ofType:nil];
    // 创建字典
    NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:path];
    // 打印版本的key
    NSLog(@"%@",[dic objectForKey:@"CFBundleVersion"]);
    
    
    // 判断
    if ([[dic objectForKey:@"CFBundleVersion"] isEqualToString:[[NSUserDefaults standardUserDefaults] valueForKey:@"version"]]) {
        
        // 版本号相同
        // 进入主页面
        self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
    }else{
        
        // 版本号不相同
        // 进入引导页
        [[NSUserDefaults standardUserDefaults] setObject:[dic objectForKey:@"CFBundleVersion"] forKey:@"version"];
        self.window.rootViewController = [[YinDaoYeViewController alloc] init];
        
        
    }

引导页界面

// 创建滚动视图
    _myScroll = [[UIScrollView alloc] initWithFrame:self.view.frame];
    _myScroll.delegate = self;
    [self.view addSubview:_myScroll];
    
    // 设置滚动范围
    _myScroll.contentSize = CGSizeMake(self.view.frame.size.width * 4, self.view.frame.size.height);
    // 取消弹簧效果
    _myScroll.bounces = NO;
    // 取消水平滚动条
    _myScroll.showsHorizontalScrollIndicator = NO;
    // 设置翻页滚动
    _myScroll.pagingEnabled = YES;
    
    // 图片数组
    _imgArr = @[@"1.jpg",@"2.jpg",@"3.jpg",@"4.jpg"];
    
    // for 循环
    for (int i = 0; i < _imgArr.count; i ++) {
        
        // 图片框
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width * i, 0, self.view.frame.size.width, self.view.frame.size.height)];
        imgView.image = [UIImage imageNamed:_imgArr[i]];
        [_myScroll addSubview:imgView];
        
        imgView.userInteractionEnabled = YES;
        
        // 在最后一张图片上加按钮
        if (i == _imgArr.count - 1) {
            
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            btn.frame = CGRectMake((self.view.frame.size.width - 100)/2, 600, 100, 30);
            [btn setTitle:@"立即体验" forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            btn.titleLabel.font = [UIFont systemFontOfSize:18];
            [btn addTarget:self action:@selector(didClick) forControlEvents:UIControlEventTouchUpInside];
            [imgView addSubview:btn];
        }
    }
    
    // 创建分页控件
    _page = [[UIPageControl alloc] initWithFrame:CGRectMake((self.view.frame.size.width - 100)/2, 670, 100, 30)];
    // 分页控件的个数
    _page.numberOfPages = _imgArr.count;
    // 所有控件的颜色
    _page.pageIndicatorTintColor = [UIColor blackColor];
    // 当前控件的颜色
    _page.currentPageIndicatorTintColor = [UIColor redColor];
    // 将分页控件添加到视图上
    [self.view addSubview:_page];

点击方法


// 立即体验按钮
-(void)didClick
{
    [self presentViewController:[[ViewController alloc] init] animated:YES completion:nil];
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    _page.currentPage = _myScroll.contentOffset.x/self.view.frame.size.width;
}
// 定时器
            NSTimer *time = [NSTimer scheduledTimerWithTimeInterval:3 repeats:YES block:^(NSTimer * _Nonnull timer) {
                
                CGFloat offsetX = _myScroll.contentOffset.x;
                // 视图的动画
                [UIView animateWithDuration:0.3 animations:^{
                    
                    if (offsetX == self.view.frame.size.width * 3) {
                        
                        _myScroll.contentOffset = CGPointMake(0, 0);
                    }else{
                        
                       _myScroll.contentOffset = CGPointMake(offsetX + self.view.frame.size.width, 0);
                    }
                }];
            }];
            
            [time fire];

你可能感兴趣的:(引导页)