新手引导页

在项目中我们经常会看到下载的应用第一进入或者更新之后再进来时会看到对本应用的一些介绍及使用,这就是新手引导,下面我们简单的实现新手引导页面;
1.创建一个继承UIWindow的类目命名为 UIWindow+Extension,然后在这个类目做我们的实现操作

#import "BSTabBarController.h"
#import "BSNewfeatureViewController.h"
#import "AppDelegate.h"

#define bundleVersionKey @"CFBundleVersion"

@implementation UIWindow (Extension)

- (void)switchRootViewController
{
    // 上一次的使用版本(存储在沙盒中的版本号)
    NSString *lastVersion = [[NSUserDefaults standardUserDefaults] objectForKey:bundleVersionKey];
    // 当前软件的版本号(从Info.plist中获得)
    NSString *currentVersion = [NSBundle mainBundle].infoDictionary[bundleVersionKey];

    if ([currentVersion isEqualToString:lastVersion]) { // 版本号相同:这次打开和上次打开的是同一个版本
        AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        app.tabBar = [[BSTabBarController alloc] init];
        self.rootViewController = app.tabBar;
    } else { // 这次打开的版本和上一次不一样,显示新特性
        self.rootViewController = [[BSNewfeatureViewController alloc] init];
    }
}

// 当前的版本号存进沙盒
- (void)saveCurrentVersion
{
    // 将当前的版本号存进沙盒
    [[NSUserDefaults standardUserDefaults] setObject:[NSBundle mainBundle].infoDictionary[bundleVersionKey] forKey:bundleVersionKey];
    [[NSUserDefaults standardUserDefaults] synchronize];
}


@end

2.在AppDelegate.h文件中,BSTabBarController是自己封装继承UITabBarController的类

@class BSTabBarController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) BSTabBarController *tabBar;

@end

3.在AppDelegate.m文件中,在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 中调用如下方法

[self.window switchRootViewController];

4."BSNewfeatureViewController.h" 中代码实现需要的效果,这里就不具体实现了

5.当用户浏览完引导界面或点击按钮进入主界面时,切换应用的主控制器

- (void)startClick
{
    // 切换到TabBarController
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    [window saveCurrentVersion];

    AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    app.tabBar = [[BSTabBarController alloc] init];
    window.rootViewController = app.tabBar;

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值