引導(dǎo)頁

判斷版本號

// 創(chuàng)始字符串
    NSString *path = [[NSBundle mainBundle] pathForResource:@"Info.plist" ofType:nil];
    // 創(chuàng)建字典
    NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:path];
    // 打印版本的key
    NSLog(@"%@",[dic objectForKey:@"CFBundleVersion"]);
    
    
    // 判斷
    if ([[dic objectForKey:@"CFBundleVersion"] isEqualToString:[[NSUserDefaults standardUserDefaults] valueForKey:@"version"]]) {
        
        // 版本號相同
        // 進(jìn)入主頁面
        self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
    }else{
        
        // 版本號不相同
        // 進(jìn)入引導(dǎo)頁
        [[NSUserDefaults standardUserDefaults] setObject:[dic objectForKey:@"CFBundleVersion"] forKey:@"version"];
        self.window.rootViewController = [[YinDaoYeViewController alloc] init];
        
        
    }

引導(dǎo)頁界面

// 創(chuàng)建滾動視圖
    _myScroll = [[UIScrollView alloc] initWithFrame:self.view.frame];
    _myScroll.delegate = self;
    [self.view addSubview:_myScroll];
    
    // 設(shè)置滾動范圍
    _myScroll.contentSize = CGSizeMake(self.view.frame.size.width * 4, self.view.frame.size.height);
    // 取消彈簧效果
    _myScroll.bounces = NO;
    // 取消水平滾動條
    _myScroll.showsHorizontalScrollIndicator = NO;
    // 設(shè)置翻頁滾動
    _myScroll.pagingEnabled = YES;
    
    // 圖片數(shù)組
    _imgArr = @[@"1.jpg",@"2.jpg",@"3.jpg",@"4.jpg"];
    
    // for 循環(huán)
    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:@"立即體驗(yàn)" 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];
        }
    }
    
    // 創(chuàng)建分頁控件
    _page = [[UIPageControl alloc] initWithFrame:CGRectMake((self.view.frame.size.width - 100)/2, 670, 100, 30)];
    // 分頁控件的個數(shù)
    _page.numberOfPages = _imgArr.count;
    // 所有控件的顏色
    _page.pageIndicatorTintColor = [UIColor blackColor];
    // 當(dāng)前控件的顏色
    _page.currentPageIndicatorTintColor = [UIColor redColor];
    // 將分頁控件添加到視圖上
    [self.view addSubview:_page];

點(diǎn)擊方法


// 立即體驗(yàn)按鈕
-(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];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容