啟動(dòng)界面之新特性

1、創(chuàng)建window分類
2、沙盒進(jìn)行版本判斷
3、新特性控制器切換

創(chuàng)建window分類,判斷版本

#import "UIWindow+ALExtension.h"
#import "ALTabBarViewController.h"
#import "ALNewViewController.h"

@implementation UIWindow (ALExtension)

- (void)switchRootViewController {
    
    // 之前已經(jīng)登錄成功過
    NSString *key = @"CFBundleVersion";
    // 上一次的使用版本(存儲(chǔ)在沙盒中的版本號(hào))
    NSString *lastVersion = [[NSUserDefaults standardUserDefaults] objectForKey:key];
    
    // 當(dāng)前軟件的版本號(hào)(info.plist中獲得)
    NSString *currentVersion = [NSBundle mainBundle].infoDictionary[key];
    
    if ([currentVersion isEqualToString:lastVersion]) {
        // 版本相同,這次打開和上次打開是同一個(gè)版本
        self.rootViewController =  [[ALTabBarViewController alloc] init];
        
    } else {
        // 這次打開的和上一次不一樣
        self.rootViewController = [[ALNewViewController alloc] init];
        
        // 將當(dāng)前的版本號(hào)存進(jìn)沙盒
        [[NSUserDefaults standardUserDefaults]setObject:currentVersion forKey:key];
        // 馬上同步到沙盒
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
    
}

新特性控制器

#import "ALNewViewController.h"
#import "ALTabBarViewController.h"

#define KWidth self.view.frame.size.width
#define KHeight self.view.frame.size.height
#define ALNewCount 4

@interface ALNewViewController () <UIScrollViewDelegate>

@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;

@property (weak, nonatomic) IBOutlet UIPageControl *pageControl;


@end

@implementation ALNewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 創(chuàng)建圖片
    for (int i = 0; i < ALNewCount; i++) {
        
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(i * KWidth, 0, KWidth, KHeight)];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"workth0%d", i + 1]];
        
        [self.scrollView addSubview:imageView];
        
        if (i == ALNewCount - 1) {
            [self setupLastImageView:imageView];
        }
        
    }
    
    self.pageControl.numberOfPages = ALNewCount;
    
    self.scrollView.contentSize = CGSizeMake(ALNewCount * KWidth, 0);
    
    
}

#pragma mark - 進(jìn)入主界面
- (void)setupLastImageView:(UIImageView *)imageView {
    
    // 開啟用戶交互
    imageView.userInteractionEnabled = YES;
    
    UIButton *enter = [[UIButton alloc] init];
    enter.frame = CGRectMake(0, KHeight - 100, KWidth, 30);
    [enter setTitle:@"進(jìn)入阿里星球之旅" forState:UIControlStateNormal];
    [enter setBackgroundImage:[UIImage imageNamed:@"nav_bg"] forState:UIControlStateNormal];
    
    [imageView addSubview:enter];
    [enter addTarget:self action:@selector(startClick) forControlEvents:UIControlEventTouchUpInside];
    
    
}

// 切換
- (void)startClick {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    window.rootViewController = [[ALTabBarViewController alloc] init];
}

#pragma UIScrollViewDelegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {

    self.pageControl.currentPage =  (int)(scrollView.contentOffset.x / scrollView.frame.size.width + 0.5);
    
    
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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